Skip to content
Prev 2103 / 10988 Next

[Rcpp-devel] data.frame from R to C++?

Hmmm. I have a bad feeling about this. I sense a disturbance in the force.

It goes down to coerceVector not doing its job on factors:

require( Rcpp )
require( inline )
v1 <- as.factor( c("c3", "c1", "c2" ) )
fx <- cfunction( signature( x = "factor" ), '
     SEXP s = PROTECT( coerceVector( x, STRSXP ) ) ;
     UNPROTECT(1);
     return s ;
' )


 > fx( as.integer( v1 ) )
[1] <NA> <NA> <NA>
Levels: c1 c2 c3

 > version
                _
platform       x86_64-apple-darwin9.8.0
arch           x86_64
os             darwin9.8.0
system         x86_64, darwin9.8.0
status         beta
major          2
minor          13.0
year           2011
month          04
day            04
svn rev        55296
language       R
version.string R version 2.13.0 beta (2011-04-04 r55296)

coerceVector is used by r_cast<STRSXP>, which is used by the ctor for 
StringVector.

...

Le 12/04/11 12:38, deqiang sun a ?crit :