[Rcpp-devel] integer and numeric vector

Romain François francoisromain at free.fr
Tue Jan 5 16:28:55 CET 2010


Hello,

I've commited Rcpp::IntegerVector and Rcpp::NumericVector. see the unit 
tests for more examples, but here's an example:

NumericVector x = {0.0,1.0,2.0,3.0} ; // this needs GCC >= 4.4
for( int i=0; i<x.size(); i++) x[i] = x[i]*2 ;
return x ;',

other constructors are available so that the class is usable before 4.4:

NumericVector x(10) ; // allocate an numeric vector of 10 elements (uses 
Rf_allocVector( REALSXP, 10 )

or the NumericVector(SEXP) which simply wraps up the SEXP into an object.

Romain

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/IW9B : C++ exceptions at the R level
|- http://tr.im/IlMh : CPP package: exposing C++ objects
`- http://tr.im/HlX9 : new package : bibtex



More information about the Rcpp-devel mailing list