I think I have run into a very specific “idiosyncrasy” with purrr environmental variables that I do not understand.
GOAL: From a function, to call save
or saveRDS
of variables in the parent frame, given we know the variable names.
PROBLEM: When the function is inside purrr::map
, it doesn’t work.
EXAMPLE:
fun <- function() {save(list = ".x", file = "/home/user/file.rdata")}
purrr::map(.x = list(iris), .f = ~fun())
error message in attached photo error message when nested in purrr
EXPECTED OUTPUT:
the function saves iris
to file
I know I am getting the correct variable and I am in the correct environment, but it feels as though .x is “unevaluated” but get
doesn’t work either. If anyone knows a way around this and why this behaviour exists that would be fantastic
Angel Liang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.