[Rcpp-devel] 4D IntegerVector constructor

Dirk Eddelbuettel edd at debian.org
Fri Jan 20 19:44:11 CET 2012


On 20 January 2012 at 10:13, Chris DuBois wrote:
| Hi all,
| 
| There was some discussion a few weeks ago about array objects.  Dirk pointed
| out that one can construct a 3d array with dims (5,3,4) using IntegerVector(
| Dimension( 5,3,4 ) ).  This works, but this doesn't seem to work for creating
| 4d arrays.  The unit tests show examples of constructing 1, 2, and 3 dimension
| arrays (in runit.Vector.R).
| 
| Is this feature hidden or unimplemented?  If unimplemented, is there a work
| around or a way to contribute?

Hmpf. 

There seems to minimal support, eg you can create an Rcpp::Dimension object
which can then be used to create a Rcpp::NumericVector:

R> library(inline)
R> 
R> f <- cxxfunction(signature(v="any"), plugin="Rcpp", body='
+    Rcpp::NumericVector X(Rcpp::Dimension(v));
+    return R_NilValue;
+ ');
R> f(rep(2,4))
NULL
R> 

... but compilation of Rcpp::wrap() trying to return it fails.


I needed something similar recently and just used RcppArmadillo's 'Cubes'
(for 3d) inside Fields (which is Matlab calls cells, I believe).   But that
was just for lookup, so you could do with Rcpp::Lists too.

I'd call this are in Rcpp 'somewhat underdeveloped' ...  If someone wants to
contribute, go have at it.

Dirk

-- 
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too
dark to read." -- Groucho Marx


More information about the Rcpp-devel mailing list