I will give you bonus points for the reproduced example and, of course, for using Rcpp :) And then I will remove them so as not to ask rcpp-devel on the list ...
As for the conversion of STL types: you don't need it, but when you decide to do it, the id as<>() true. The only "best way" I can come up with is to look for names, as in R itself:
require(inline) require(Rcpp) set.seed(42) xl <- list(U=runif(4), N=rnorm(4), T2df=rt(4,2)) fun <- cxxfunction(signature(x="list"), plugin="Rcpp", body = ' Rcpp::List xl(x); std::vector<double> u = Rcpp::as<std::vector<double> >(xl["U"]); std::vector<double> n = Rcpp::as<std::vector<double> >(xl["N"]); std::vector<double> t2 = Rcpp::as<std::vector<double> >(xl["T2df"]); // do something clever here return(R_NilValue); ')
Hope this helps. Otherwise, the list is always open ...
PS As for the two-dimensional array, this is more complicated, since there is no built-in C ++ two-dimensional array. If you really want to do linear algebra, check out RcppArmadillo and RcppEigen .
source share