[Rcpp-devel] Returning an arma vec
Dirk Eddelbuettel
edd at debian.org
Wed Dec 3 18:14:06 CET 2014
This is known, documented / has been discussed before, and hard to change now
given that 100 CRAN packages depend on RcppArmadillo and its existing interface.
You could write your own converter to SEXP and use that.
Dirk
On 3 December 2014 at 11:59, Gabor Grothendieck wrote:
| 1. This returns a matrix rather than a vector:
|
| -- start of file teste.cpp ---
| #include <RcppArmadillo.h>
| // [[Rcpp::depends(RcppArmadillo)]]
|
| using namespace arma;
| using namespace Rcpp;
|
| // [[Rcpp::export]]
| NumericVector teste(const vec& x) {
| vec v = x.subvec(1, 2); // x
| return wrap(v); // x
| }
| /*** R
| teste(1:4)
| */
| --- end of file teste.cpp ---
|
| Now run in R:
|
| > sourceCpp("teste.cpp", rebuild = TRUE)
|
| > teste(1:4)
| [,1]
| [1,] 2
| [2,] 3
|
|
| 2. If we replace the lines marked // x with
|
| return wrap(x.subvec(1, 2));
|
| then it fails with a compiler error.
|
| error: cannot convert 'const arma::subview_col<double>' to 'SEXP' in
| initialization
|
|
| --
| Statistics & Software Consulting
| GKX Group, GKX Associates Inc.
| tel: 1-877-GKX-GROUP
| email: ggrothendieck at gmail.com
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
More information about the Rcpp-devel
mailing list