On 25 September 2012 at 13:53, Rodney Sparapani wrote: | You just need an explicit type conversion like so: | | funk2 <- cxxfunction(body='RNGScope scope; | NumericVector rn(5); | for (int i=0; i < 5; i++) rn[i] = as<double>(rnorm(1,0,1)); | return wrap(rn);', | includes="using namespace Rcpp;\n", plugin="Rcpp") | | funk2()
In the interest of constructive criticism, my version (and I must posted essentially the same maybe ten times already on this very list): R> f3 <- cxxfunction(signature(), plugin="Rcpp", body=' + RNGScope scope; + NumericVector rn = Rcpp::rnorm(5,0,1); + return wrap(rn); + ') R> f3() [1] -0.837983 -0.706765 0.551781 0.662024 0.495562 R> Changes: -- no 'using namespace Rcpp;' as inline already does it; I still don't use it as I prefer to be explicit about provenance of functions and objects -- no loop (as Doug said) --- rnorm() is a sugar functions and vectorised -- no wrap, we already have an Rcpp vector for which wrap is implicit 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