On 14 August 2013 at 15:57, Matteo Fasiolo wrote: | thank you very much for your replies. In the end a named vector is | enough for my purpose: | | cppFunction( | ' | NumericVector myVett(NumericVector x = NumericVector::create(0) ) | { | if(x.size() == 0) x = NumericVector::create(_["a"] = 1.0, _["b"] = 2.0); | return x; | } | ' | )
You don't even need the assignment in the function definition: R> cppFunction("NumericVector matteo(NumericVector x) { if (x.size()==0) x = NumericVector(4); return(x); }") R> matteo(vector()) [1] 0 0 0 0 R> matteo(1:3) [1] 1 2 3 R> Dirk -- Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com _______________________________________________ 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