the following code
require(R6)
Array <- R6Class(
"Array",
public=list(
x=matrix(0,0,0),
initialize=function(a,b,c){
self$x <- matrix(a,b,c)
},
assign=function(z){
self$x[1,1] <- z
invisible(self)
}
)
)
x <- Array$new(0,10,10)
tracemem(x$x)
x$assign(1)
y <- matrix(0,10,10)
tracemem(y)
y[1,1] <- 1
yields this output
> [1] "<0x55ae7be40040>"
> tracemem[0x55ae7be40040 -> 0x55ae7b403700]: <Anonymous>
> > [1] "<0x55ae7b254c90>"
> >
which implies that when the R6 member array is updated a copy of the array is made, whereas when the plain array is updated, the element is update "in-place" (i.e. no copy is generated).
Any idea how I can achieve this for the R6 object?