Hi all,<div><br></div><div>I'm looking for better ways of dealing with lists of objects. If I have a list s, I want to be able to so an operation like:</div><div>s["hello"][3,3] <- 100</div><div>where I replace the (3,3) element with 100. Below I show the way I've done this so far, but for large lists I don't want to have to manually create new objects every time. Is there a better way to cast every object in an Rcpp::List?</div>
<div><br></div><div>Thanks,</div><div>Chris<br><div><br></div><div><div>library(inline)</div><div>library(Rcpp)</div><div>fx <- cxxfunction(,"",includes=</div><div>'</div><div>// Take the element of s named "hello" and put 100 in the (2,2) element</div>
<div>Rcpp::List listExample(Rcpp::List s) {</div><div> Rcpp::NumericMatrix sm = s["hello"];</div><div> sm(2,2) = 100;</div><div> s["hello"] = sm;</div><div> return s;</div><div>}</div><div>RCPP_MODULE(foo){</div>
<div> function( "listExample", &listExample ) ;</div><div>}</div><div>', plugin="Rcpp")</div><div><br></div><div>foo <- Module("foo",getDynLib(fx))</div><div><br></div><div>s <- list(hello=matrix(1:9,3,3))</div>
<div>foo$listExample(s)</div></div></div>