[Rcpp-devel] NumericVector

James Li jamesyili at gmail.com
Fri Aug 16 17:59:28 CEST 2013


Dear Dirk and Rcpp-devel members,

I am currently passing a multidimensional (N > 2) array (i.e.
array(NA, dim = rep(3,5)) ) from R via Rcpp using

"in C++:"

//[[Rcpp::export]]
Rcpp::List check_arrayC (Rcpp::NumericVector x, Rcpp::IntegerVector modes){
//do stuff to x
    return Rcpp::List::create(Rcpp::_["data"] = x, Rcpp::_["modes"] = modes);
}


"in R:"

a <- array(1:32, dim=rep(2,5))
b <- check_arrayC(a, dim(a))

While I know that a multidimensional array is stored as a contiguous
array internally, is there currently a more natural/efficient way to
pass it back and forth within Rcpp?

Also from Dirk's book, it seems that an instance of
Rcpp::NumericVector can be instantiated into a multidimensional array
via

Rcpp::NumericVector vec3 =Rcpp::NumericVector( Rcpp::Dimension(4, 5, 6));

In this case, how do we access element vec3[1,2,3]?

Some background about what I am trying to do: I would like to create a
multidimensional array wrapper class around the base R multi-way array
class. I would also like to be able to pass this multidimensional
array via Rcpp to do all the heavy-lifting in c++. Ideally, I could
also convert the mda into a Boost::multi_array.

Thanks in advance for any help.

-James

-- 
James Li | Ph.D. Candidate | http://jamesyili.com/
Dept. of Statistical Science | Cornell University


More information about the Rcpp-devel mailing list