[Rcpp-devel] NumericVector Double mismatch when indexing an array
Goldfeld, Keith
Keith.Goldfeld at nyumc.org
Tue Sep 25 21:11:31 CEST 2012
Of course - that did the trick. Thanks so much.
-----Original Message-----
From: Rodney Sparapani [mailto:rsparapa at mcw.edu]
Sent: Tuesday, September 25, 2012 2:53 PM
To: Goldfeld, Keith
Cc: 'rcpp-devel at lists.r-forge.r-project.org'
Subject: Re: [Rcpp-devel] NumericVector Double mismatch when indexing an array
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
More information about the Rcpp-devel
mailing list