[Rcpp-devel] Returning an arma vec
Gabor Grothendieck
ggrothendieck at gmail.com
Wed Dec 3 17:59:29 CET 2014
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
More information about the Rcpp-devel
mailing list