[Rcpp-devel] How to give default value with Rcpp and roxygen2 involving seq_len

JJ Allaire jj.allaire at gmail.com
Wed Jan 13 16:49:36 CET 2016


The parsing of default values for attributes has some significant
limitations (it's mostly just use for literals and empty vectors).
This is what is currently supported:

• String literals delimited by quotes (e.g. "foo")
• Decimal numeric values (e.g. 10 or 4.5)
• Pre-defined constants including true, false, R_NilValue, NA_STRING,
NA_INTEGER, NA_REAL, and NA_LOGICAL.
• Selected vector types (CharacterVector, IntegerVector, and
NumericVector) instantiated using the empty form of the ::create
static member function.
• Matrix types instantiated using the rows, cols constructor.


On Wed, Jan 13, 2016 at 10:41 AM, Lafaye de Micheaux Pierre
<lafaye at dms.umontreal.ca> 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.
>
> Best regards,
>
> Pierre
>
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


More information about the Rcpp-devel mailing list