Lists

  • A list overall, has it’s own reference (id)
  • List elements also each point to other values
  • List doesn’t store the value, it stores a reference to the value
  • As of R 3.1.0, modifying lists creates a shallow copy
    • References (bindings) are copied, but values are not
l1 <- list(1, 2, 3)
l2 <- l1
l2[[3]] <- 4
  • We can use ref() to see how they compare
    • See how the list reference is different
    • But first two items in each list are the same
ref(l1, l2)
#> █ [1:0x560e545079d8] <list> 
#> ├─[2:0x560e5450e658] <dbl> 
#> ├─[3:0x560e5450e498] <dbl> 
#> └─[4:0x560e5450e2d8] <dbl> 
#>  
#> █ [5:0x560e539fda38] <list> 
#> ├─[2:0x560e5450e658] 
#> ├─[3:0x560e5450e498] 
#> └─[6:0x560e5450d008] <dbl>