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




_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to