Hi all,

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:
s["hello"][3,3] <- 100
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?

Thanks,
Chris

library(inline)
library(Rcpp)
fx <- cxxfunction(,"",includes=
'
// Take the element of s named "hello" and put 100 in the (2,2) element
Rcpp::List listExample(Rcpp::List s) {
  Rcpp::NumericMatrix sm = s["hello"];
  sm(2,2) = 100;
  s["hello"] = sm;
  return s;
}
RCPP_MODULE(foo){
  function( "listExample", &listExample ) ;
}
', plugin="Rcpp")

foo <- Module("foo",getDynLib(fx))

s <- list(hello=matrix(1:9,3,3))
foo$listExample(s)
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to