Dear all I am trying to find the best way to handle large fields in reference classes.
As the code below shows assignment via <<- causes many copies to be made if the subsetting is extensive (in modb1). This can cause R to run out of memory. Creating a local copy and using the optimisation in <- is the best solution I have found so far (in modb2) - but it is not really much better than ordinary functions using call by value and then reassigning. Is there a reason why optimisation does not occur for <<- ? Or is their a better solution for reference classes? Regards Giles A <- setRefClass("A", fields=list(b="vector")) A$methods( initialize=function() { b <<- 1:10000 }, modb1=function() { # simple subsetting for illustration for(i in 2:length(b)) b[i] <<- b[i-1] + 1 }, modb2=function() { bb <- b for(i in 2:length(b)) bb[i] <- bb[i-1] + 1 b <<- bb } ) a <- new("A") tracemem(a$b) a$modb1() a$modb2() [[alternative HTML version deleted]] ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel