To get a std::vector<float>
out of your NumericMatrix
, you can use:
std::vector<float> dat = Rcpp::as<std::vector<float> >(data);
The numbers in this vector will be stored as they are stored in the matrix in R (e.g. matrix(1:4, nrow=2)
will result in a vector 1 2 3 4
). If you need the transpose, I would suggest calling t
from within R.
All that remains for your problem is converting the vector
into a C-style raw pointer. This can be done with:
float* _data = &dat[0];
Some words of warning about grabbing raw vectors out of std::vector
objects: if you later added objects to dat
or deleted dat
, the _data
pointer could become invalid.
You can grab the other parameters through similar use of the Rcpp::as
function:
int _dataXsize = Rcpp::as<int>(xSize);
int _dataYsize = Rcpp::as<int>(ySize);
std::vector<int> _testIndexes = Rcpp::as<std::vector<int> >(tIndexes);
std::vector<int> _controlIndexes = Rcpp::as<std::vector<int> >(cIndexes);