[Rcpp-devel] moving lists between functions in a package

Scott Monroe monroeleescott at gmail.com
Fri Dec 27 21:36:16 CET 2013


I am trying to figure out how to create a package where I have one function
call another, which returns a list.  Some example .cpp code is below.  If I
just compile the first function, everything is fine.  When I add the second
function, I get errors.  I'm sure I'm using the Rcpp::List syntax
incorrectly, but I haven't had luck finding an example of how to do this.

Again, I'd like to be able to call the first function from the second, grab
the results from the returned list, and do further computations.

Thanks, Scott


#include <RcppArmadillo.h>
using namespace Rcpp ;
// [[Rcpp::depends(RcppArmadillo)]]

// [[Rcpp::export]]
List check_C(NumericMatrix B) {
  arma::mat A = Rcpp::as<arma::mat>(B);
  int p = A.n_cols;
  arma::mat AA = A*A;
  arma::vec X = A.col(0);

  return Rcpp::List::create(Rcpp::Named("X")=X, Rcpp::Named("AA")=A,
Rcpp::Named("p")=p);
}

// [[Rcpp::export]]
List check_C(NumericMatrix A) {
  Rcpp::List L = check_C(A);

  return Rcpp::List::create(Rcpp::Named("A")=A);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20131227/f2b19036/attachment.html>


More information about the Rcpp-devel mailing list