[Rcpp-devel] access to element of generic data frame

Dirk Eddelbuettel edd at debian.org
Tue Jun 26 03:39:37 CEST 2012


On 25 June 2012 at 17:43, Antonio Piccolboni wrote:
| Hi,
|  is there a a way to access a specific element of a data frame in Rcpp without
| previous knowledge of the type of the columns? I see from RcppExamples that one
| can do something like:
| 
| // construct the data.frame object
| Rcpp::DataFrame DF = Rcpp::DataFrame(Dsexp);
| // and access each column by name
| Rcpp::IntegerVector a = DF["a"];
| a[2] = 42;
| 
| which accesses DF[2, "a"] using the R syntax. Unfortunately, I don't have the
| advance knowledge that column "a" will be an integer. I am trying to write some
| code that would work for any frame. Suggestions? Thanks

Well, C++ is a strongly-typed language.  So eventually you need to assign to
/some/ type.  You can always try to test using the collection of macros in
the R's C-level API as for example Rf_isInteger() and friends.

Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com  


More information about the Rcpp-devel mailing list