<div dir="ltr">Just a suggestion re: recursion with Rcpp, yet another nice way we can recurse is through using the sugar lapply:<br><br><div>-----</div><div><br></div><div>#include <Rcpp.h></div><div>using namespace Rcpp;</div>
<div><br></div><div>// [[Rcpp::export]]</div><div>RObject add_attr(RObject x_) {</div><div>  RObject x = clone(x_);</div><div>  if (is<List>(x)) {</div><div>    x = wrap( lapply( as<List>(x), add_attr ) );</div>
<div>  } else {</div><div>    x.attr("type") = "Other";</div><div>  }</div><div>  return x;</div><div>}</div><div>  </div><div>/*** R</div><div>add_attr( list(x=list(a=1, b=2, c=3), y=list( list( d=4 ) ) ) )</div>
<div>*/</div><div><br></div><div>-----</div><div><br></div><div>If we want to operate on specific elements as well, we can use is<T> and as<T> together, and then operate on objects as needed.</div><div><br></div>
<div>It lets us avoid an explicit for loop, and 'feels' more like R.</div><div><br></div><div>-Kevin</div></div>