title: How to return multiple objects from Rcpp back to R?
body: <p>This may be a very basic request, but I have a Rcpp function in R that calculates various matrices which I want to pass back to R.  My code looks like this:</p>
  
  <pre><code>zeromatrix &lt;- matrix(0,6,1)
  east &lt;- matrix(seq(1:48),6,8)
  west &lt;- matrix(seq(1:48),6,8)
  func &lt;- 'NumericMatrix eastC(NumericMatrix e, NumericMatrix w, NumericMatrix zeromatrix) {
  int ecoln=e.ncol();
  int ecolnlessone = ecoln - 1;
  NumericMatrix eout(e.nrow(),e.ncol()) ;
  for (int j = 0;j &lt; ecoln;j++) {
  if (j &gt; 0) {
  eout(_,j) = e(_,j-1);
  } else {
  eout(_,j) = e(_,0);
  }
  }
  eout(_,0) = zeromatrix(_,0);
  return eout;
  
  NumericMatrix wout(w.nrow(),w.ncol()) ;
  for (int j = 0;j &lt; ecoln;j++) {
  if (j &lt; ecolnlessone) {
  wout(_,j) = w(_,j+1);
  } else {
  wout(_,j) = w(_,j);
  }
  }
  wout(_,ecolnlessone) = zeromatrix(_,0);
  return wout;
  }'
  cppFunction(func)
  
  d &lt;- eastC(east, west, zeromatrix)
  </code></pre>
  
  <p>I want both 'eout' and 'wout' to be passed back to R but obviously only the last returned value is passed back (i.e. wout).  So d becomes wout.  How do I extract multiple objects (i.e. eout and wout in this case)?  I did see in Dirk's introduction sheets to Rcpp and it had something about list(ret) but when I tried this my code wouldn't compile.  Any help would be hugely appreciated?</p>