[Rcpp-devel] Default value for Rcpp List
Dirk Eddelbuettel
edd at debian.org
Wed Aug 14 13:29:46 CEST 2013
On 14 August 2013 at 11:42, Matteo Fasiolo wrote:
| Dear Rcpp users,
|
| a very simple question: I have a function that has a Rcpp::List
| among its arguments, and I would like to set a default values for
| that List.
| Unfortunately this code:
|
| cppFunction(
| '
| List myList(List x = List::create(_["a"] = 1, _["b"] = 2))
| {
| return x;
| }
| '
| )
|
| raises the warning:
|
|
| Warning message:
| Unable to parse C++ default value 'List::create(_["a"] = 1, _["b"] = 2)' for argument x of function myList
| >
| > myList()
| Error in .Primitive(".Call")(<pointer: 0xb5907fb0>, x) : 'x' is missing
|
|
| Similar code with NumericVector works fine:
|
| cppFunction(
| '
| NumericVector myVett(NumericVector x = NumericVector::create(3))
| {
| return x;
| }
| '
| )
|
| myVett()
| # [1] 0 0 0
Not really. You just allocated space, not values.
I suspect this doesn't work the way you want it to.
| Am I doing something wrong? Thanks!
You could create the objects "empty", test in the function body for emptyness
and set values.
Dirk
| ----------------------------------------------------------------------
| _______________________________________________
| 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
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel
mailing list