[Rcpp-devel] Rcpp::DataFrame and factors

Romain Francois romain at r-enthusiasts.com
Thu May 6 09:29:39 CEST 2010


Hi,

The new Rcpp::DataFrame follows R's tradition and automatically converts 
character vectors into factors:

 > fun <- cppfunction( signature(), '
+         IntegerVector v = IntegerVector::create(1,2,3);
+         std::vector<std::string> s(3);
+         s[0] = "a";
+         s[1] = "b";
+         s[2] = "c";
+ return DataFrame::create(Named("a")=v, Named("b")=s);
+ ' )
 > fun()
   a b
1 1 a
2 2 b
3 3 c
 > fun()[["b"]]
[1] a b c
Levels: a b c


Is this good or bad ? I think it is bad as we don't have a way to turn 
this off... we can set the options( "stringsAsFactors" ) to FALSE

Should we allow something like this:

DataFrame::create(
	_["x"] = v ,
	_["y"] = s,
	_["stringsAsFactors"] = false )

or maybe have a variable like this to pilot the option:

static bool DataFrame::stringsAsFactors = false ;

Romain

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/9aKDM9 : embed images in Rd documents
|- http://tr.im/OIXN : raster images and RImageJ
|- http://tr.im/OcQe : Rcpp 0.7.7



More information about the Rcpp-devel mailing list