Retrieve parameters from List using Rcpp <p>New to Rcpp I am testing how to retrieve and use a nested list from R with a known structure without copying parts of the list again. The small code example (with embedded R code) seems to work (cout is used for debugging). </p> <p>The list rL retrieved from R may be very big so I do not want to reallocate memory (copy parts of rL). Do the current code copy parts of rL?</p> <p>Best Lars</p> <pre><code>#include &lt;Rcpp.h&gt; #include &lt;iostream&gt; using namespace Rcpp; using namespace std; // [[Rcpp::export]] SEXP testing(const List rL) { List L(rL); SEXP sL2(L["L2"]); List L2(sL2); SEXP sStateGrpL2(L2["stateGroups"]); List stateGrpL2(sStateGrpL2); SEXP sStateAllocL2(L2["stateAlloc"]); CharacterVector stateAllocL2(sStateAllocL2); SEXP sActionGrpL2(L2["actionGroups"]); List actionGrpL2(sActionGrpL2); SEXP sActionAllocL2(L2["actionAlloc"]); List actionAllocL2(sActionAllocL2); vector&lt;string&gt; stateLabels; vector&lt;string&gt; actionLabels; CharacterVector actionNames; for(int n2 = 0; n2&lt; as&lt;int&gt;(L2["stages"]); n2++) { stateLabels = as&lt; vector&lt;string&gt; &gt;(stateGrpL2[as&lt;string&gt;(stateAllocL2[n2])]); int s2Size = stateLabels.size(); SEXP sAllocA(actionAllocL2[n2]); List allocA(sAllocA); actionNames = as&lt;CharacterVector&gt;(allocA[0]); cout &lt;&lt; "stage:" &lt;&lt; n2 &lt;&lt; " sN:" &lt;&lt; as&lt;string&gt;(stateAllocL2[n2]) &lt;&lt; "\n"; for (int s2=0; s2&lt;s2Size; ++s2) { cout &lt;&lt; " s:" &lt;&lt; stateLabels[s2] &lt;&lt; " aN:" &lt;&lt; actionNames[s2] &lt;&lt; "\n"; actionLabels = as&lt; vector&lt;string&gt; &gt;(actionGrpL2[ as&lt;string&gt;(actionNames[s2]) ]); int a2Size = actionLabels.size(); for (int a2=0; a2&lt;a2Size; ++a2) { cout &lt;&lt; " a:" &lt;&lt; actionLabels[a2] &lt;&lt; "\n"; } } } return wrap(0); } /*** R L &lt;- list( L2=list(stages=2, stateGroups=list(s1Grp=c("a","b","c"),s2Grp=c("d","e")), stateAlloc = c(rep("s1Grp",1),rep("s2Grp",1)), actionGroups = list(a1Grp=c("terminate","keep"), a2Grp=c("finish")), actionAlloc = list(list( rep("a1Grp",3) ), list( c("a1Grp","a2Grp") ) ) ) ) testing(L) */ </code></pre>