Consider the following list:
example_list <- list(x = 1, y = 2, z = 3)
There are multiple ways to extract items from example_list
; for example, example_list$x
or example_list[["x"]]
will work.
It is also possible to extract items from example_list
by calling $
directly, i.e.,
`$`(example_list, "x")
However, the following does not work:
bork <- "x"
`$`(example_list, bork) ## Returns NULL
`$`(example_list, eval(bork)) ## Returns error: invalid subscript type 'language'
How can I call $
directly with variable item names?
R version 4.4.0