environment
Environment Access

Description

These functions are related to R environments.

Usage

environment(fun = NULL)
environment<-(fun, value)
globalenv()
emptyenv()
baseenv()
is.environment(x)
new.env(hash = TRUE, parent = parent.frame(), size = 29L)
parent.env(env)
parent.env<-(env, value)
environmentName(env)

Arguments

fun the function. The default is NULL.
value the environment to associate with the function specified by the fun.
x an object.
env an environment.
hash this argument is ignored.
parent the enclosing environment.
size this argument is ignored.

Details

environment() works as follows: environment<-(fun, value) sets the environment specified by value and returns the modified function closure, as follows: parent.env() checks whether env is an environment. It works as follows: new.env() creates the new environment with the specified parent environment. It returns an error if parent is not an environment.
parent.env <- (env, value) sets the parent environment of the environment env to value, and returns env. It returns errors in the following cases: environmentName() returns the character string representing the name of the environment, as follows:
Value
environment returns the environment name associated with the function fun. If fun is NULL, it returns the current environment where it is executed.
baseenv returns the environment of the base package.
globalenv returns the global environment.
emptyenv returns the empty environment.
is.environment returns TRUE if x is an environment; otherwise it returns FALSE.
new.env returns a new environment.
parent.env returns the parent environment of env.
parent.env <- returns env.
environmentName returns the name of environment env.
Examples
environment(lm)

environment()

fn <- function(x) x+1 environment(fn) <- new.env() environment(fn)

x <- 1 attr(x, ".Environment") <- "myenv" environment(x) # [1] "myenv"

baseenv()

globalenv()

emptyenv()

new.env(parent = emptyenv())

is.environment(new.env(parent = emptyenv()))

parent.env(globalenv())

parent.env(new.env(parent = emptyenv()))

environmentName(globalenv())

Package base version 6.1.4-13
Package Index