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 | e...@debian.org _______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel