Examples for 'base::environment'


Environment Access

Aliases: environment environment<- .GlobalEnv globalenv emptyenv baseenv is.environment new.env parent.env parent.env<- .BaseNamespaceEnv environmentName env.profile enclosure

Keywords: data programming

### ** Examples

f <- function() "top level function"

##-- all three give the same:
environment()
<environment: 0x55ccff4c2e50>
environment(f)
<environment: 0x55ccff4c2e50>
.GlobalEnv
<environment: R_GlobalEnv>
ls(envir = environment(stats::approxfun(1:2, 1:2, method = "const")))
[1] "f"      "method" "na.rm"  "x"      "y"      "yleft"  "yright"
is.environment(.GlobalEnv) # TRUE
[1] TRUE
e1 <- new.env(parent = baseenv())  # this one has enclosure package:base.
e2 <- new.env(parent = e1)
assign("a", 3, envir = e1)
ls(e1)
[1] "a"
ls(e2)
character(0)
exists("a", envir = e2)   # this succeeds by inheritance
[1] TRUE
exists("a", envir = e2, inherits = FALSE)
[1] FALSE
exists("+", envir = e2)   # this succeeds by inheritance
[1] TRUE
eh <- new.env(hash = TRUE, size = NA)
with(env.profile(eh), stopifnot(size == length(counts)))

[Package base version 4.2.3 Index]