pos.to.env
Convert Positions in the Search Path to Environments

Description

Gives the corresponding environment for the specified position from the search() list.

Usage

pos.to.env(x)

Arguments

x an integer value, or a vector of integer values. x is limited to the number of environments present in the search() list, plus environment: R_EmptyEnv.
Value
returns one object or a list of objects of the class "environment". These objects can have one or two attributes:
name the package name corresponding to environment. For example: "package:graphics"
path the absolute path of a package corresponding to environment. For example: "C:/xxxx/library/graphics"
Note
The path is not present for global environment, Autoloads, base and empty environments. The position after the last environment in search path is returned as empty environment.
See Also
as.environment, search
Examples
pos.to.env(1:5)

pos.to.env(4)

pos.to.env(10) # <environment: R_EmptyEnv>

pos.to.env(.GlobalEnv) # Error: environments cannot be coerced to other types

pos.to.env(c(1, 2, 3))

pos.to.env(-1) # Error in pos.to.env(-1) : no enclosing environment

f <- function() { pos.to.env(-1) } f() # <environment: R_GlobalEnv>

pos.to.env(0) # Error in pos.to.env(0) : invalid argument

pos.to.env(10) # <environment: R_EmptyEnv>

pos.to.env(11) # Error in pos.to.env(11) : invalid argument

# Passing a list object. pos.to.env(list(a = c(1:3), b = c(4:5))) # Error: (list) object cannot be coerced to type 'integer'

Package base version 6.0.0-69
Package Index