Coerce to an Environment Object (original) (raw)
as.environment {base} | R Documentation |
---|
Description
A generic function coercing an R object to an[environment](../../base/help/environment.html)
. A number or a character string is converted to the corresponding environment on the search path.
Usage
as.environment(x)
Arguments
x | an R object to convert. If it is already an environment, just return it. If it is a positive number, return the environment corresponding to that position on the search list. If it is -1, the environment it is called from. If it is a character string, match the string to the names on the search list. If it is a list, the equivalent of list2env(x, parent = emptyenv()) is returned. If is.object(x) is true and it has a classfor which an as.environment method is found, that is used. |
---|
Details
This is a primitive generic function: you can write methods to handle specific classes of objects, see InternalMethods.
Value
The corresponding environment object.
Author(s)
John Chambers
See Also
[environment](../../base/help/environment.html)
for creation and manipulation,[search](../../base/help/search.html)
;[list2env](../../base/help/list2env.html)
.
Examples
as.environment(1) ## the global environment
identical(globalenv(), as.environment(1)) ## is TRUE
try( ## <<- stats need not be attached
as.environment("package:stats"))
ee <- as.environment(list(a = "A", b = pi, ch = letters[1:8]))
ls(ee) # names of objects in ee
utils::ls.str(ee)
[Package _base_ version 4.6.0 Index]