Understanding tracemem
But does this? z <- as.list(x) z$a <- 11
Yes of course, as z is now of length 11. There is no provision in R to extend a vector except by creating a new one. (Well, there is at C level but I think it is not currently used.)
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
Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/