[Rcpp-devel] RInside input pointers to arrays

Allison Irvine a.irvine2 at gmail.com
Thu Oct 15 00:12:44 CEST 2015


I am trying to figure out how to avoid creating a copy of an array in 
c++ to a Rcpp::NumericVector or std::vector in order to use the data in 
an embedded R instance (RInside object). It is clear that one can copy 
an array in C++ to a Rcpp::NumericVector, then assign a variable in the 
embedded R object, for example:


double myArray[5] = {1,2,3,4,5};
Rcpp::NumericVector myNumericVector(5);
for (int i=0; i<5; i++) {
         myNumericVector[i] = myArray[i];
}
RInside R(argc, argv);
R["x"] = myNumericVector;

However, I would like to avoid having to create a copy of the array. Is 
there a way to assign the "x" variable in the above example using 
pointers to the C++ array "myArray"?

Also, I am interested in doing the inverse of that. Is it possible to 
take the output of the embedded R code called by R.parseEval() and have 
it return the values to a pre-allocated array in c++?






More information about the Rcpp-devel mailing list