[Rcpp-devel] Dealing with 2-dimensional vectors

Leo Alekseyev dnquark at gmail.com
Mon Feb 15 10:23:36 CET 2010


>> 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 needs better documentation, but what you can do is :
>
> vector<int> dims = sig_actions.attr("dim") ;

Ah, thank you.  I forgot about automatic type conversions and somehow
thought that an explicit cast was necessary (i.e.
(vector<int>)s_a.attr("dim")), which led to an ambiguity error.
That's it, I'm dusting off my _Thinking in C++_ book :)

> The proxy classes are designed to be invisible, you should not really access
> them directly.

Good point; I was only using it to better understand what was going on.


On a somewhat different note, do you have any plans to support
multidimensional arrays (or is it something that I missed in the API?)
 (Or is there a particular reason to avoid heavy use of
multidimensional arrays in R?)

--Leo


More information about the Rcpp-devel mailing list