[Rcpp-devel] Rcpp shortcut for R's as.matrix and as.vector
Douglas Bates
bates at stat.wisc.edu
Mon Mar 29 15:36:37 CEST 2010
Most Lapack routines for solving linear systems from factorizations
allow the right hand side to be a matrix, thereby providing for
solving multiple systems in one call. I would like to preserve this
capability while also allowing for the most common case where the rhs
is a vector. Also, I would like to return a vector solution rather
than a single matrix solution when it is a single column.
I can accomplish these "as.matrix" and "as.vector" translations by
calling the corresponding R functions.
static Rcpp::Function asMatrix("as.matrix")
static Rcpp::Function asVector("as.vector")
and using those within Rcpp. Is there an alternative within Rcpp? I
realize that I need to return another object so that it can have a
different class within C++ but I guess I would like
NumericMatrix mat = Rcpp::as<NumericMatrix>(myNumericVector);
or something similar. It is not a big deal because the calls to the R
function are not a problem (or I could manipulate the SEXP internally)
but I'm wondering if I am missing something simple here.
More information about the Rcpp-devel
mailing list