title: Fast access to Rcpp::List elements
body: <p>I have a data set that I really want to work with as a 3D array.  Rather than deal with an attempt to get an R array into a RcppArmadillo Cube, which I'm not sure would work (?), I'm sending in a list of matrices.  My problem, however, is that the list is of large matrices and I want to be able to loop over the 3rd dimension in the middle of loops over rows or columns.  With medium size matrices (list of 20 matrices of size 50,000x5), flattening the list into one long array gets me my result in less than a second.</p>
  
  <p>I'd prefer to avoid copying the data in order to accommodate larger matrices.  But using as&lt; NumericMatrix >(list_obj[t]) inside a loop over the rows makes the function take several minutes at least.  An example of my code use as&lt;> that is incredibly slow is below.  dat is the list sent into the function. steps is an int sent into the function.</p>
  
  <pre><code>T = dat.size()
  N = as&lt;NumericMatrix&gt;(dat[0]).nrow()
  M = as&lt;NumericMatrix&gt;(dat[0]).ncol()
  
  // Temp vals                                                                  
  double top, bot;
  
  // Output vector                                                              
  NumericVector out(M);
  
  // Loop through each signal                                                   
  for (int j=0; j&lt;M; j++) {
      // Reset numerator and denominator                                          
      top = 0;
      bot = 0;
  
      // Loop through each time dimension                                         
      for (int tm = 0; tm &lt; (T - steps); tm++) {
  
          // Loop through each row                                                  
          for (int i = 0; i &lt; N; i++) {
  
              // Check if entry is positive                                           
              if (as&lt;NumericMatrix&gt;(dat[tm])(i, j) &gt; 0) {
                  // Increment denominator                                              
                  bot += 1.0;
                  // Compute future product                                             
                  top = 1.0;
                  for (int k = 1; k &lt;= steps; k++) {
                      if (as&lt;NumericMatrix&gt;(dat[tm + k])(i, j) == 0) {
                          top = 0.0;
                          break;
                      }
                  }
              }
          }
          out(j) = top / bot;
      }
  }
  </code></pre>
  
  <p>Is there a fast way to do this without flattening the matrix and requiring a full copy of the potentially large data?</p>