[Rcpp-devel] Returning an arma vec

Romain Francois romain at r-enthusiasts.com
Wed Dec 3 18:30:47 CET 2014


Envoyé de mon iPhone

> Le 3 déc. 2014 à 17:59, Gabor Grothendieck <ggrothendieck at gmail.com> a écrit :
> 
> 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

This should be easy/trivial to fix for someone with the right skills. 

Romain

> 
> -- 
> 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


More information about the Rcpp-devel mailing list