Problem:
I need a function which takes only one argument, but needs access to some other variables. I don't want to store these in the .GlobalEnv
.
Current Solution: Use a function which takes all needed arguments, that create another function which adapt the environment.
Example:
library(rlang)
foo <- function(a, b){
bar <- function(c){
out <- a + b + c
out
}
set_env(bar, get_env())
bar
}
bar <- foo(1, 2)
bar(3)
I strongly believe that this approach have downsides, but I can't put my finger on what these downsides might be. I would be happy if you could help me.