Given list
li = list(a = list(b = list(1:3)))
the following extraction methods give identical result:
li[["a"]][["b"]][[1]][[2]]
[1] 2
purrr::pluck(li, "a", "b", 1, 2)
[1] 2
for (i in list("a", "b", 1, 2)) li = `[[`(li, i)
li
[1] 2
purrr::pluck
and for
have the obvious advantage that one can construct a vector of nested indices programmatically. Is there anything to consider when comparing them in terms of:
- performance (eg. is the "chained"
[[
method significantly different/faster from thefor
method?) - edge cases where one way might provide a different result from the others