On 09/25/2012 01:37 PM, Goldfeld, Keith wrote:
code<- 'Rcpp::RNGScope scope;
+ Rcpp::NumericVector rn(5);
+ for (int i=0; i< 5; i++) {
+ rn(i) = rnorm(1,0,1);
+ }
+ return Rcpp::wrap(rn);
+ '
fun<- cxxfunction(body=code, plugin="Rcpp")
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()
--
Rodney Sparapani, PhD Center for Patient Care and Outcomes Research
Sr. Biostatistician http://www.mcw.edu/pcor
4 wheels good, 2 wheels better! Medical College of Wisconsin (MCW)
WWLD?: What Would Lombardi Do? Milwaukee, WI, USA
_______________________________________________
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