Copy-on-modify
- If you modify a value bound to multiple names, it is ‘copy-on-modify’
- If you modify a value bound to a single name, it is ‘modify-in-place’
- Use
tracemem()
to see when a name’s value changes
y <- x
y[[3]] <- 4L # Changes (copy-on-modify)
#> tracemem[0x557c2b539558 -> 0x557c2ba4a948]: eval eval withVisible withCallingHandlers eval eval with_handlers doWithOneRestart withOneRestart withRestartList doWithOneRestart withOneRestart withRestartList doWithOneRestart withOneRestart withRestartList withRestarts <Anonymous> evaluate in_dir in_input_dir eng_r block_exec call_block process_group withCallingHandlers <Anonymous> process_file <Anonymous> <Anonymous> render_cur_session <Anonymous>
y[[3]] <- 5L # Doesn't change (modify-in-place)
Turn off tracemem()
with untracemem()
Can also use
ref(x)
to get the address of the value bound to a given name