[Rd] coerce SEXP type to C++ matrix class and back

Antonio Perez antonio.pv.gs at gmail.com
Mon Jan 11 17:54:50 CET 2016


Dirk,

I am sorry if it sounded disrespectful. On the contrary, as I said,
your packages Rcpp and RcppArmadillo work very well, and use both of
them in more "complex" applications. However, in this particular case
in which I have just one object of one type (matrix double) with its
elements stored column-major similarly to R I though that could find a
reasonable method to coerce my SEXP matrix into a Matrix double in
armadillo without using two packages for this.

I hope this is understood.



I though that there might beI ptough that might result which I insist
has similar and , a matrix with one typeit seems veryas we say
literally in Spanishother

2016-01-11 13:53 GMT+01:00 Dirk Eddelbuettel <edd at debian.org>:
>
> I don't want to sound disrespectful, but why not use RcppArmadillo if
> simplicity is you goal?
>
> It is hard to beat the _fully automatic_ conversion:
>
> R> cppFunction("arma::mat doubleUp(const arma::mat & x) { return 2*x; }", depends="RcppArmadillo")
> R> doubleUp(matrix(1:9,3,3))
>      [,1] [,2] [,3]
> [1,]    2    8   14
> [2,]    4   10   16
> [3,]    6   12   18
> R>
>
> You can of course do all that by hand too, but why do you think both Rcpp and
> RcppArmadillo have, respectively, tens of thousands of lines of code?
>
> Dirk
>
> --
> http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org



More information about the R-devel mailing list