[Rcpp-devel] Dealing with 2-dimensional vectors

Romain Francois romain at r-enthusiasts.com
Mon Feb 15 10:28:26 CET 2010


On 02/15/2010 10:23 AM, Leo Alekseyev wrote:
>>> 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.

Sure.

> 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?)

There are plans. I'd like to support indexing with arbitrary number of 
indices. Other things are more urgent, but if you submit some patch, 
I'll have a look.

> --Leo
>


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/OcQe : Rcpp 0.7.7
|- http://tr.im/O1wO : highlight 0.1-5
`- http://tr.im/O1qJ : Rcpp 0.7.6



More information about the Rcpp-devel mailing list