According to Hadley Wickham's Advanced R, an object with a single binding shouldn't get copied when it's modified (chapter 2.5.1). On my system, however, I can't see that modify-in-place optimisation is applied in this instance
x <- c(1,2,3)
tracemem(x)
#> "<0x10c3b16f8>"
x[[3]] <- 4
#> tracemem[0x10c3b16f8 -> 0x10b9305a8]:
That is, x
is not supposed to be copied when it's modified by x[[3]] <- 4
.
What am I getting wrong? Why doesn't R use modify-in-place optimisation in this example?
Edit: Added session info
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.5
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] lobstr_0.0.0.9000
loaded via a namespace (and not attached):
[1] compiler_3.5.0 tools_3.5.0 yaml_2.2.0 Rcpp_1.0.0 rlang_0.3.0.9000