Skip to content
Prev 951 / 10988 Next

[Rcpp-devel] speed

Le 04/08/10 21:56, Douglas Bates a ?crit :
Actually, what happens here is that the IntegerVector( int ) constructor 
gets called which creates a vector of the requested size:

 > fx <- cxxfunction( , 'IntegerVector x = 10 ; return x ;', plugin = 
"Rcpp" )
 > fx()
  [1] 0 0 0 0 0 0 0 0 0 0

So Richard's code works because of two mistakes that sort of balance 
each other.


Creating an IntegerVector of length one with an int can be done using 
IntegerVector::create, as in:

 > fx <- cxxfunction( , 'IntegerVector x = IntegerVector::create( 10 ) ; 
return x ;', plugin = "Rcpp" )
 > fx()
[1] 10

Romain