Bind functions of the current environment to a target environment
Source:R/utilities.R
bind_fn_2_env.Rd
This function is equivalent to environment(fn) <- env
. Hence functions
must bind to names.
Examples
# Access the associated environment inside a function
self <- NULL
e <- new.env()
# The associated environment needs to have a reference to itself
e$self <- e
e$show_self <- function() return(self)
# The function can only access the global variable `self`
e$show_self()
#> NULL
# Bind the function to the environment `e`
bind_fn_2_env(env = e, e$show_self)
# Both point to the same environment
e$show_self()
#> <environment: 0x125ffeb98>
e
#> <environment: 0x125ffeb98>