as.environment
Coerce to an Environment Object

### Description

Coerce the package name, position of the package in the search list, or a list to a corresponding environment.

### Usage

    as.environment(x)

### Arguments

x | an environment, a character string, integer value (or vector of integer), or a list with names.

### Details

as.environment is a primitive function.

- If x is an environment, as.environment returns x.
- If x is a character string, as.environment matches the string with "GlobalEnv" and "package:base" and, if the match is successful, returns the corresponding environment.
- If x is a character string, but does not match "GlobalEnv" and "package:base", as.environment searches every environment on the search list, gets the name attribute of each environment, and compares each name attribute with the input x. If this search is successful, as.environment returns that match. Otherwise, it reports an error.
- If x is of type integer or real, as.environment calls pos.to.env(), which gets the environment, given the position in the list of packages in search.

Value
returns either one object or a list of objects of the class "environment". These objects can have one or both of the following attributes:

- name: The package name corresponding to the environment. For example: "package:graphics".
- path: The absolute path of a package corresponding to the environment. For example: "C:/xxxx/library/graphics".

See Also
pos.to.env, search
Examples

    objects(as.environment(list(x=999, y=888)))
    as.environment("package:stats")
    as.environment(2)
    pos.to.env(2)   # Same as as.environment(2)

Package base version 6.1.5-18
Package Index