[Rcpp-devel] How to give default value with Rcpp and roxygen2 involving seq_len
Dirk Eddelbuettel
edd at debian.org
Wed Jan 13 17:04:41 CET 2016
On 13 January 2016 at 16:41, Lafaye de Micheaux Pierre wrote:
| Hello everybody,
|
| Let's consider the simple function:
|
| f <- function(x = 1:10) {return(x)}
|
| where the argument 'x' could take non integer values.
|
| I would like to create such a function using Rcpp and roxygen2. If I try
| something like:
|
| //' @param x Vector of real values
| NumericVector f(NumericVector x) {return(x);}
|
| then after creation using devtools, I will obtain a function like this
| one:
| f <- function(x) {return(x)}
|
| How can I write things in my C++ code so that I will obtain
| the x = 1:10 default values?
|
| I tried something like:
| //' @param x Vector of real values
| NumericVector f(NumericVector x = NumericVector::create(seq_len(10))
| {return(x);}
|
| but it failed completely ...
|
| I am quite new to Rcpp, so I apologize if my question is too naive. If
| this is the case, feel free to send me a web link to some documentation
| that I could learn to try to solve this problem by myself.
I am sure I have more examples by one quick check lead to RcppApt where I do
//' The APT Package Management system uses a data-rich caching
//' structure. This accessor function returns the names of installable
//' packages for a given regular expression.
//'
//' @title Retrieve Names of All Installable Packages
//' @param regexp Regular expression for package name
//' @return A data frame with columns containing the
//' package name, the installed version (or NA if not installed)
//' and the section it is installed in (or NA).
//' @author Dirk Eddelbuettel
//' @examples
//' getPackages("^r-(base|doc)-")
// [[Rcpp::export]]
Rcpp::DataFrame getPackages(const std::string regexp = ".") {
...
See https://github.com/eddelbuettel/rcppapt
What you have above is one-level tricker as it uses Rcpp constructs. I am not
sure I tried that. I most just initialized standard C++ types: bool, string, ...
Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
More information about the Rcpp-devel
mailing list