[Rcpp-devel] Transform arbitrary R object into std::vector<vector<double>>
Paul Saary
rcpp at paulsaary.de
Thu May 19 14:47:23 CEST 2016
Thank you for your reply,
> If you always use vector< vector< double > > then I would start with
> Rcpp::NumericMatrix, or arma::mat.
The problem is, that I want to offer the user a choice of using also
data.frames and not just Matrices. So I can not really decide, with what
I start, or am I wrong?
Regarding the use of Rcpp:function:
As the R objects used are very large (many MB to some GB), I would like
to do the transformation into a usable format, in my case into the
vector< vector< double > >, in CPP, as I imagine it to be much faster.
I will have look into armadillo, but I hoped to avoid loading another
library, to reduce the depencies of my script/package.
Paul
On 19.05.2016 12:07, Dirk Eddelbuettel wrote:
>
> On 19 May 2016 at 10:46, Paul Saary wrote:
> | Hello,
> |
> | I have been trying to solve this problem for quite some time now, so I
> | thought I'd ask here.
> |
> | I am trying to write a Cpp function, accepting multiple input types,
> | such as matrices and dataframes.
> |
> | I understood that I could do this by accepting any SEXP object.
> |
> | The core problem now is to transform these object into something my
> | software can use, which would be an object of type
> | std::vector<vector<double>>.
>
> If you always use vector< vector< double > > then I would start with
> Rcpp::NumericMatrix, or arma::mat.
>
> Do you know if you prefer rows or columns? It is pretty easy to pick off
> either rows and columns, but you may save yourself a transpose.
>
> Lastly, maybe consider switching your code to arma::mat instead of vector<
> vector< double > > which is really a fudge to make up for the lack of proper
> Matrix classes in C++ itself.
>
> On 19 May 2016 at 11:12, Sameer D'Costa wrote:
> | Have you considered using the function as.matrix? It is an R function but you
> | can call it from within your Rcpp code as well. Once you have a matrix you can
> | use your matrix solution.
>
> I'd consider Rcpp::Function as a last resort. You do not need it here.
>
> Dirk
>
More information about the Rcpp-devel
mailing list