adv-r
adv-r copied to clipboard
Copy number in exercise 2 from 2.3.6
Great book Hadley, I'm really enjoying it, but I think there's an issue with exercise 2 from 2.3.6 and from this stack exchange question I don't think I'm alone. In R 3.6.0 from the console on mac the example code only triggers one copy.
> x <- c(1L, 2L, 3L)
> tracemem(x)
[1] "<0x7fc03bbc0008>"
> x[[3]] <- 4
tracemem[0x7fc03bbc0008 -> 0x7fc0379f4e28]:
While using x <- 1:3 triggers the expected 2 copies
> x <- 1:3
> tracemem(x)
[1] "<0x7fc03bad3fd0>"
> x[[3]] <- 4
tracemem[0x7fc03bad3fd0 -> 0x7fc03bbc0048]:
tracemem[0x7fc03bbc0048 -> 0x7fc0379f5008]:
After reading https://www.brodieg.com/2019/02/18/an-unofficial-reference-for-internal-inspect/ I think it has to do with differences in reference counting, but honestly I'm the person on chapter 2 of your book so that tells you my level of sophistication.