[Rcpp-devel] Dealing with 2-dimensional vectors

Leo Alekseyev dnquark at gmail.com
Mon Feb 15 06:42:43 CET 2010


Hi all,

I got a chance to play with Rcpp some more this weekend.  I like it!
The one thing that I found a little awkward, however, is dealing with
matrices -- while the new API's SimpleVector indexes them just fine, I
wish it had provided accessors similar to the old API's
RcppMatrix<T>.rows()/cols().

I can get the dimensions attribute via Rcpp::RObject's attr() method,
but that took some digging to figure out -- mostly because I can't
seem to get the cast operator to work properly.  Here is how I get the
dimensions currently:

Rcpp::RObject::AttributeProxy sa_dims_ap(sig_actions.attr("dim"));
vector<int> sa_dims2(Rcpp::as< vector<int> >(sa_dims_ap));
Rprintf("sig_actions has dims %d,%d\n",sa_dims2[0],sa_dims2[1]);

This seems to involve a cast to SEXP via AttributeProxy's operator
SEXP().  The following, however, doesn't compile:
vector<int> sa_dims3((vector<int>)sa_dims_ap);
Rprintf("sig_actions has dims %d,%d\n",sa_dims3[0],sa_dims3[1]);

TradingLoopPCA.cpp:257: error: call of overloaded
‘vector(Rcpp::RObject::AttributeProxy&)’ is ambiguous

Any pointers on what I'm doing wrong here?

Thanks,
--Leo


More information about the Rcpp-devel mailing list