title: R List of numeric vectors -> C++ 2d array with Rcpp
body: <p>I mainly use R, but eventually would like to use Rcpp to interface with some C++ functions that take in and return 2d numeric arrays. So to start out playing around with C++ and Rcpp, I thought I'd just make a little function that converts my R list of variable-length numeric vectors to the C++ equivalent and back again.</p>
  
  <pre><code>require(inline)
  require(Rcpp)
  
  test1 = cxxfunction(signature(x='List'), body = 
  '
    using namespace std;
    List xlist(x);
    int xlen = xlist.size();
    vector&lt; vector&lt;int&gt; &gt; xx;
    for(int i=0; i&lt;xlen; i++) {
      vector&lt;int&gt; test = as&lt;vector&lt;int&gt; &gt; (xlist[i]);
      xx.push_back(test);
    }
    return(wrap(xx));
  '
  , plugin='Rcpp')
  </code></pre>
  
  <p>This works like I expect:</p>
  
  <pre><code>&gt; test1(list(1:2, 4:6))
  [[1]]
  [1] 1 2
  
  [[2]]
  [1] 4 5 6
  </code></pre>
  
  <p>Admittedly I am only part way through the very thorough documentation, but <strong>is there a nicer (i.e. more Rcpp-like) way to do the R -> C++ conversion than with the for loop?</strong> I am thinking possibly not, since the documentation mentions that (at least with the built-in methods) <code>as</code> "offers less flexibility and currently handles conversion of R objects into primitive types", but I wanted to check because I'm very much a novice in this area.</p>