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

Dirk Eddelbuettel edd at debian.org
Fri Dec 27 21:51:08 CET 2013


On 27 December 2013 at 12:36, Scott Monroe wrote:
| 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);

A comes in as a matrix, now you are trying to make it a List -- that won't.  

Plus, as Simon, observed you may want to rename the functions a little.

Dirk

| 
|   return Rcpp::List::create(Rcpp::Named("A")=A);
| }
| 
| 
| 
| 
| ----------------------------------------------------------------------
| _______________________________________________
| 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
-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list