Skip to content
Prev 43646 / 63424 Next

Understanding tracemem

I guess a better example is

z <- list(a = 1:1e6, b = runif(1e6))
z$c <- 1

The list gets copied, but do a and b, or does the new list point to
the existing locations?  The following test suggests that it's a deep
copy.

x <- 1:1e7
z <- list(a = x)

system.time(replicate(100, z$b <- 1L)) / 100
# ~ 0.05s
system.time(replicate(100, x[1e6 + 1L] <- 1L)) / 100
# ~ 0.04s

Hadley