Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

fn_env

Return the closure environment of a function


Description

Closure environments define the scope of functions (see env()). When a function call is evaluated, R creates an evaluation frame (see ctxt_stack()) that inherits from the closure environment. This makes all objects defined in the closure environment and all its parents available to code executed within the function.

Usage

fn_env(fn)

fn_env(x) <- value

Arguments

fn, x

A function.

value

A new closure environment for the function.

Details

fn_env() returns the closure environment of fn. There is also an assignment method to set a new closure environment.

Examples

env <- child_env("base")
fn <- with_env(env, function() NULL)
identical(fn_env(fn), env)

other_env <- child_env("base")
fn_env(fn) <- other_env
identical(fn_env(fn), other_env)

rlang

Functions for Base Types and Core R and 'Tidyverse' Features

v0.4.11
MIT + file LICENSE
Authors
Lionel Henry [aut, cre], Hadley Wickham [aut], mikefc [cph] (Hash implementation based on Mike's xxhashlite), Yann Collet [cph] (Author of the embedded xxHash library), RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.