R - Environment Access
R - Environment Access
R - Environment Access
html
Environment Access
Description
Usage
environment(fun = NULL)
environment(fun) <- value
is.environment(x)
.GlobalEnv
globalenv()
.BaseNamespaceEnv
emptyenv()
baseenv()
parent.env(env)
parent.env(env) <- value
environmentName(env)
env.profile(env)
Arguments
fun
a function, a formula, or NULL, which is the default.
value
an environment to associate with the function
x
an arbitrary R object.
hash
a logical, if TRUE the environment will use a hash table.
parent
an environment to be used as the enclosure of the environment created.
env
an environment
size
an integer specifying the initial size for a hashed environment. An internal default value
will be used if size is NA or zero. This argument is ignored if hash is FALSE.
1 of 3 17/Sep/2017, 4:58 PM
R: Environment Access http://127.0.0.1:31810/library/base/html/environment.html
Details
When get or exists search an environment with the default inherits = TRUE, they look for the
variable in the frame, then in the enclosing frame, and so on.
The global environment .GlobalEnv, more often known as the user's workspace, is the first item
on the search path. It can also be accessed by globalenv(). On the search path, each item's
enclosure is the next item.
The object .BaseNamespaceEnv is the namespace environment for the base package. The
environment of the base package itself is available as baseenv().
If one follows the chain of enclosures found by repeatedly calling parent.env from any
environment, eventually one reaches the empty environment emptyenv(), into which nothing may
be assigned.
The replacement form of environment, is.environment, baseenv, emptyenv and globalenv are
primitive functions.
System environments, such as the base, global and empty environments, have names as do the
package and namespace environments and those generated by attach(). Other environments can
be named by giving a "name" attribute, but this needs to be done with care as environments have
unusual copying semantics.
Value
If fun is a function or a formula then environment(fun) returns the environment associated with
that function or formula. If fun is NULL then the current evaluation environment is returned.
The replacement form sets the environment of the function or formula fun to the value given.
new.env returns a new (empty) environment with (by default) enclosure the parent frame.
environmentName returns a character string, that given when the environment is printed or "" if it
2 of 3 17/Sep/2017, 4:58 PM
R: Environment Access http://127.0.0.1:31810/library/base/html/environment.html
env.profile returns a list with the following components: size the number of chains that can be
stored in the hash table, nchains the number of non-empty chains in the table (as reported by
HASHPRI), and counts an integer vector giving the length of each chain (zero for empty chains).
This function is intended to assess the performance of hashed environments. When env is a non-
hashed environment, NULL is returned.
See Also
ls may be used to view the objects in an environment, and hence ls.str may be useful for an
overview.
Examples
is.environment(.GlobalEnv) # TRUE
3 of 3 17/Sep/2017, 4:58 PM