Learn R Programming

bandicoot (version 1.0.0)

bind_fn_2_env: Bind functions of the current environment to a target environment

Description

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

Usage

bind_fn_2_env(env, ...)

Value

No return value, called for side effects.

Arguments

env

Environment.

...

Functions.

Details

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

Examples

Run this code
# 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()

# 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()
e

Run the code above in your browser using DataLab