Skip to contents

This function is equivalent to environment(fn) <- env. Hence functions must bind to names.

Usage

bind_fn_2_env(env, ...)

Arguments

env

Environment.

...

Functions.

Value

No return value, called for side effects.

Details

Pass character function names to ... will cause error.

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>