<div dir="ltr">Thanks so much.  Sorry for the silly error in the example.  The following works, and has the basic functionality I'm looking for.<div><br></div><div><div>#include <RcppArmadillo.h></div><div>using namespace Rcpp ;</div>
<div>// [[Rcpp::depends(RcppArmadillo)]]</div><div><br></div><div>// [[Rcpp::export]]</div><div>List check_B(arma::mat B) {</div><div>  int p = B.n_cols;</div><div>  arma::mat BB = B*B;</div><div>  arma::vec X = B.col(0);</div>
<div><br></div><div>  return Rcpp::List::create(Rcpp::Named("X")=X, Rcpp::Named("BB")=BB, Rcpp::Named("p")=p);</div><div>}</div><div><br></div><div>// [[Rcpp::export]]</div><div>List check_A(NumericMatrix A) {</div>
<div>  arma::mat B = Rcpp::as<arma::mat>(A);</div><div>  Rcpp::List L = check_B(B);</div><div>  arma::mat CC = L["BB"];</div><div><br></div><div>  return Rcpp::List::create(Rcpp::Named("B")=B, Rcpp::Named("CC")=CC);</div>
<div>}</div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Dec 27, 2013 at 12:51 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
On 27 December 2013 at 12:36, Scott Monroe wrote:<br>
| I am trying to figure out how to create a package where I have one function<br>
| call another, which returns a list.  Some example .cpp code is below.  If I<br>
| just compile the first function, everything is fine.  When I add the second<br>
| function, I get errors.  I'm sure I'm using the Rcpp::List syntax incorrectly,<br>
| but I haven't had luck finding an example of how to do this.<br>
|<br>
| Again, I'd like to be able to call the first function from the second, grab the<br>
| results from the returned list, and do further computations.<br>
|<br>
| Thanks, Scott<br>
|<br>
|<br>
| #include <RcppArmadillo.h><br>
| using namespace Rcpp ;<br>
| // [[Rcpp::depends(RcppArmadillo)]]<br>
|<br>
| // [[Rcpp::export]]<br>
| List check_C(NumericMatrix B) {<br>
|   arma::mat A = Rcpp::as<arma::mat>(B);<br>
|   int p = A.n_cols;<br>
|   arma::mat AA = A*A;<br>
|   arma::vec X = A.col(0);<br>
|<br>
|   return Rcpp::List::create(Rcpp::Named("X")=X, Rcpp::Named("AA")=A,<br>
| Rcpp::Named("p")=p);<br>
| }<br>
|<br>
| // [[Rcpp::export]]<br>
| List check_C(NumericMatrix A) {<br>
|   Rcpp::List L = check_C(A);<br>
<br>
</div></div>A comes in as a matrix, now you are trying to make it a List -- that won't.<br>
<br>
Plus, as Simon, observed you may want to rename the functions a little.<br>
<br>
Dirk<br>
<div class="im"><br>
|<br>
|   return Rcpp::List::create(Rcpp::Named("A")=A);<br>
| }<br>
|<br>
|<br>
|<br>
|<br>
</div>| ----------------------------------------------------------------------<br>
<div class="HOEnZb"><div class="h5">| _______________________________________________<br>
| Rcpp-devel mailing list<br>
| <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
| <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
Dirk Eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a><br>
</font></span></blockquote></div><br></div>