[Rcpp-devel] Accessing data frame information within Rcpp (question from Stack Overflow)
timp2012 at hotmail.com
Mon Jun 11 15:42:38 CEST 2012
Thanks for that Dirk.
First comment: unless I'm mistaken there sounds like there could be significant overlap with the
thread http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2012-May/003802.html where
the comment came:
"What we...need is to be able to
1. access the value of an Rcpp list entry by name.
2. recover the basic type, integer or floating point
3. recover the dimensions
4. recover the values as a vector"
This feels almost the same as what I'm asking, in terms of getting information effectively from the
Initially the situation struck me as very curious. You've gone to the trouble of passing a data frame
over to C++, and it's sat there with all the column names available, and all the data in it, and
presumably also all the data types. But you can't directly access the data. Ok, you've made me
accept this (however bizarre it may seem). So now I'm thinking: what is the best strategy to
get at the data in the general case?
Perhaps let me rephrase things as broadly as possible: what would be the best strategy to generate
from that data frame a collection of named objects that you CAN access? Let's say the notation
or object type is completely irrelevant to me - but somehow, I want to be able to access whatever was
in my "dragonCount" column using - in some way - the name "dragonCount" (not a column number).
Obviously, one strategy is to manually define individual vectors, one at a time, for each column in
the data frame. This is what I did in my example. But this doesn't seem like it should be the best
or most intelligent way. If there's 200 columns, that process requires 200 lines and looks pretty
horrendous. Even a n00b like me knows that's not how code should look.
So, even if the original Rcpp::DataFrame object doesn't permit access, surely there's some way
of solving the general case by setting up an object in C++ (vector of vectors?) and populating
it systematically from the DF object? Maybe by looping over the names in the DF object and adding
in the vectors one by one? I'm an R coder rather than a C++ coder so I'm coming to you fellows
cap in hand, asking whether this is possible.
I'm not asking for Rcpp to do this automatically - I'm simply asking how one should approach the
problem. Coming from the R side, I also genuinely think anyone who wishes to use Rcpp with large
data frames will be extremely interested in the answer.
Cheers for now,
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Rcpp-devel