hadley/adv-r

What did auther say in section of 2.3.1 of Chapter "Name and Value"and what R acturally showed were different

Feng-Zhang opened this issue · 1 comments

Why are what auther said different form what R acturally showed:

rm(list=ls())
x <- c(1, 2, 3)
cat(tracemem(x), "\n")
y <- x
y[[3]] <- 4L
y[[3]] <- 5L
untracemem(x)

The step y[[3]] <- 5L should not copy the x because it is modify-in-place optimisation not copy-on-modify.

However, in my R it still copied the x as showed below:

> rm(list=ls())
> x <- c(1, 2, 3)
> cat(tracemem(x), "\n")
<000001D212DE2F28> 
> y <- x
> y[[3]] <- 4L
tracemem[0x000001d212de2f28 -> 0x000001d2120e3e68]: 
> y[[3]] <- 5L
tracemem[0x000001d2120e3e68 -> 0x000001d211f4b4a0]: 
> untracemem(x)

Any help or suggestion would be apprciated.

I test the above code in R console, it is no problem. However, running the above code in RStudio, the inconsistency appear.