# NOT RUN {
## class "myIter" has a BigData field for the real (big) data
## and a "twiddle" field for some parameters that it twiddles
## ( for some reason)
myIter <- setRefClass("myIter", contains = "localRefClass",
fields = list(BigData = "numeric", twiddle = "numeric"))
tw <- rnorm(3)
x1 <- myIter(BigData = rnorm(1000), twiddle = tw) # OK, not REALLY big
twiddler <- function(x, n) {
x$ensureLocal() # see the Details. Not really needed in this example
for(i in seq(length = n)) {
x$twiddle <- x$twiddle + rnorm(length(x$twiddle))
## then do something ....
## Snooping in gdb, etc will show that x$BigData is not copied
}
return(x)
}
x2 <- twiddler(x1, 10)
stopifnot(identical(x1$twiddle, tw), !identical(x1$twiddle, x2$twiddle))
# }
Run the code above in your browser using DataLab