Skip to content

Commit 895ba44

Browse files
committed
Moved section down & fixed syntax highlight on old max post
1 parent 5a0edee commit 895ba44

File tree

1 file changed

+57
-56
lines changed

1 file changed

+57
-56
lines changed

vignettes/Rcpp-FAQ.Rnw

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,9 @@ library paths. A solution is outlined
668668

669669
In short, you want to add this entry to your \texttt{~/.R/Makevars}:
670670

671-
\begin{verbatim}
671+
<<lang=bash>>=
672672
FLIBS=`gfortran -print-search-dirs | grep ^libraries: | sed 's|libraries: =||' | sed 's|:| -L|g' | sed 's|^|-L|'`
673-
\end{verbatim}
673+
@
674674

675675
This invocation explicitly asks and constructs the library link paths
676676
from the \texttt{gfortran}'s reported search paths, and produces a set
@@ -693,60 +693,6 @@ exposure to a number of advanced Rcpp users. The
693693
Several dozen fully documented examples are provided at the
694694
\href{http://gallery.rcpp.org}{Rcpp Gallery} -- which is also open for new contributions.
695695

696-
\subsection{Can I use default function parameters with \pkg{Rcpp}?}
697-
698-
Yes, you can use default parameters with \textit{some} limitations.
699-
The limitations are mainly related to string literals and empty vectors.
700-
This is what is currently supported:
701-
702-
\begin{itemize}
703-
\item String literals delimited by quotes (e.g. \code{"foo"})
704-
\item Integer and Decimal numeric values (e.g. \code{10} or \code{4.5})
705-
\item Pre-defined constants including:
706-
\begin{itemize}
707-
\item Booleans: \code{true} and \code{false}
708-
\item Null Values: \code{R_NilValue}, \code{NA_STRING},
709-
\code{NA_INTEGER}, \code{NA_REAL}, and \code{NA_LOGICAL}.
710-
\end{itemize}
711-
\item Selected vector types can be instantiated using the empty form of the
712-
\code{::create} static member function.
713-
\begin{itemize}
714-
\item \code{CharacterVector}, \code{IntegerVector}, and
715-
\code{NumericVector}
716-
\end{itemize}
717-
\item Matrix types instantiated using the rows, cols constructor \code{Rcpp::<Type>Matrix n(rows,cols)}
718-
\begin{itemize}
719-
\item \code{CharacterMatrix}, \code{IntegerMatrix}, and
720-
\code{NumericMatrix})
721-
\end{itemize}
722-
\end{itemize}
723-
724-
To illustrate, please consider the following example that provides a short
725-
how to:
726-
727-
<<lang=cpp>>=
728-
#include <Rcpp.h>
729-
730-
// [[Rcpp::export]]
731-
void sample_defaults(NumericVector x = NumericVector::create(), // Size 0 vector
732-
bool bias = true, // Set to true
733-
std::string method = "rcpp rules!"){ // Default string
734-
Rcpp::Rcout << "x size: " << x.size() << ", ";
735-
Rcpp::Rcout << "bias value: " << bias << ", ";
736-
Rcpp::Rcout << "method value: " << method << std::endl;
737-
}
738-
739-
/*** R
740-
sample_defaults() # all defaults
741-
sample_defaults(1:5) # supply x values
742-
sample_defaults(bias = FALSE,
743-
method = "rstats") # supply bool and string
744-
*/
745-
@
746-
747-
Note: In \code{cpp}, the default \code{bool} values are \code{true} and
748-
\code{false} whereas in R the valid types are \code{TRUE} or \code{FALSE}.
749-
750696

751697
\subsection{Can I use templates with \pkg{Rcpp} ? }
752698

@@ -1238,6 +1184,61 @@ concering data.frame creation with \pkg{Rcpp}. One solution offers a custom
12381184
\code{ListBuilder} class to circumvent the limit; another suggests to simply
12391185
nest lists.
12401186

1187+
\subsection{Can I use default function parameters with \pkg{Rcpp}?}
1188+
1189+
Yes, you can use default parameters with \textit{some} limitations.
1190+
The limitations are mainly related to string literals and empty vectors.
1191+
This is what is currently supported:
1192+
1193+
\begin{itemize}
1194+
\item String literals delimited by quotes (e.g. \code{"foo"})
1195+
\item Integer and Decimal numeric values (e.g. \code{10} or \code{4.5})
1196+
\item Pre-defined constants including:
1197+
\begin{itemize}
1198+
\item Booleans: \code{true} and \code{false}
1199+
\item Null Values: \code{R_NilValue}, \code{NA_STRING},
1200+
\code{NA_INTEGER}, \code{NA_REAL}, and \code{NA_LOGICAL}.
1201+
\end{itemize}
1202+
\item Selected vector types can be instantiated using the empty form of the
1203+
\code{::create} static member function.
1204+
\begin{itemize}
1205+
\item \code{CharacterVector}, \code{IntegerVector}, and
1206+
\code{NumericVector}
1207+
\end{itemize}
1208+
\item Matrix types instantiated using the rows, cols constructor \code{Rcpp::<Type>Matrix n(rows,cols)}
1209+
\begin{itemize}
1210+
\item \code{CharacterMatrix}, \code{IntegerMatrix}, and
1211+
\code{NumericMatrix})
1212+
\end{itemize}
1213+
\end{itemize}
1214+
1215+
To illustrate, please consider the following example that provides a short
1216+
how to:
1217+
1218+
<<lang=cpp>>=
1219+
#include <Rcpp.h>
1220+
1221+
// [[Rcpp::export]]
1222+
void sample_defaults(NumericVector x = NumericVector::create(), // Size 0 vector
1223+
bool bias = true, // Set to true
1224+
std::string method = "rcpp rules!"){ // Default string
1225+
Rcpp::Rcout << "x size: " << x.size() << ", ";
1226+
Rcpp::Rcout << "bias value: " << bias << ", ";
1227+
Rcpp::Rcout << "method value: " << method << std::endl;
1228+
}
1229+
1230+
/*** R
1231+
sample_defaults() # all defaults
1232+
sample_defaults(1:5) # supply x values
1233+
sample_defaults(bias = FALSE,
1234+
method = "rstats") # supply bool and string
1235+
*/
1236+
@
1237+
1238+
Note: In \code{cpp}, the default \code{bool} values are \code{true} and
1239+
\code{false} whereas in R the valid types are \code{TRUE} or \code{FALSE}.
1240+
1241+
12411242

12421243
\section{Support}
12431244

0 commit comments

Comments
 (0)