Similar to this question:
Return elements of list as independent objects in global environment
I cannot seem to adapt the answer to assign the list elements when list2env
is called inside a function:
E.g.
lst <- list(a = c(1, 2), b = c(3, 4))
tmp_fn <- function(lst) {
# do computations on list elements
# first assign each to the function environment
list2env(lst, parent = parent.frame()) # fails
# do stuff
...
}
I thought the parent = parent.frame()
would work, but while debugging tmp_fn
I only see that lst
gets assigned to the function environment as a list, not the individual variables a
and b
.