22 setembro, 2021
# Ambiente amb1 <- new.env() # Verificando os seus parentais rlang::env_parents(amb1, last = emptyenv())
## [[1]] $ <env: global> ## [[2]] $ <env: package:stats> ## [[3]] $ <env: package:graphics> ## [[4]] $ <env: package:grDevices> ## [[5]] $ <env: package:utils> ## [[6]] $ <env: package:datasets> ## [[7]] $ <env: package:methods> ## [[8]] $ <env: Autoloads> ## [[9]] $ <env: package:base> ## [[10]] $ <env: empty>
# Promessa makeCluster autoload("makeCluster", "parallel") # Caminho de busca sem o pacote 'parallel' search() ## [1] ".GlobalEnv" "package:stats" "package:graphics" ## [4] "package:grDevices" "package:utils" "package:datasets" ## [7] "package:methods" "Autoloads" "package:base"
# Verificamos que 'makeCluster' esta como promessa ls("Autoloads") ## [1] "makeCluster" # Chamando a funcao makeCluster ## function (spec, type = getClusterOption("type"), ...) ## { ## switch(type, PSOCK = makePSOCKcluster(names = spec, ...), ## FORK = makeForkCluster(nnodes = spec, ...), SOCK = snow::makeSOCKcluster(names = spec, ## ...), MPI = snow::makeMPIcluster(count = spec, ...), ## NWS = snow::makeNWScluster(names = spec, ...), stop("unknown cluster type")) ## } ## <bytecode: 0x000000000769b808> ## <environment: namespace:parallel> # Verificando novamente o Caminho de busca, # agora com o pacote 'parallel' search() ## [1] ".GlobalEnv" "package:parallel" "package:stats" ## [4] "package:graphics" "package:grDevices" "package:utils" ## [7] "package:datasets" "package:methods" "Autoloads" ## [10] "package:base"
x <- c(1, 2, 4) mean(x)
## [1] 2.333333
# Ambiente amb1 <- new.env(hash = FALSE) # Inserindo objetos nesse ambiente amb1$a <- c(1, 2, 4); amb1$b <- "a"; amb1$d <- TRUE # Inspecao do objeto. Internal(inspect(amb1)) ## @0x000000000db22758 04 ENVSXP g0c0 [REF(1)] <0x000000000db22758> ## FRAME: ## @0x000000000db213a8 02 LISTSXP g0c0 [REF(1)] ## TAG: @0x00000000078ebb28 01 SYMSXP g0c0 [MARK,REF(128)] "d" ## @0x000000000db1fa38 10 LGLSXP g0c1 [REF(3)] (len=1, tl=0) 1 ## TAG: @0x000000000db1c4b8 01 SYMSXP g0c0 [REF(10)] "b" ## @0x000000000db1fae0 16 STRSXP g0c1 [REF(3)] (len=1, tl=0) ## @0x0000000006369e78 09 CHARSXP g0c1 [MARK,REF(14),gp=0x61] [ASCII] [cached] "a" ## TAG: @0x0000000006483320 01 SYMSXP g0c0 [MARK,REF(60)] "a" ## @0x000000000db186f8 14 REALSXP g0c3 [REF(1)] (len=3, tl=0) 1,2,4 ENCLOS: ## @0x0000000005fda628 04 ENVSXP g0c0 [MARK,REF(65535),GL,gp=0x8000] <R_GlobalEnv>
amb1$a[2] <- 10 .Internal(inspect(amb1)) ## @0x000000000db22758 04 ENVSXP g0c0 [REF(1)] <0x000000000db22758> ## FRAME: ## @0x000000000db213a8 02 LISTSXP g0c0 [REF(1)] ## TAG: @0x00000000078ebb28 01 SYMSXP g0c0 [MARK,REF(128)] "d" ## @0x000000000db1fa38 10 LGLSXP g0c1 [REF(3)] (len=1, tl=0) 1 ## TAG: @0x000000000db1c4b8 01 SYMSXP g0c0 [REF(10)] "b" ## @0x000000000db1fae0 16 STRSXP g0c1 [REF(3)] (len=1, tl=0) ## @0x0000000006369e78 09 CHARSXP g0c1 [MARK,REF(16),gp=0x61] [ASCII] [cached] "a" ## TAG: @0x0000000006483320 01 SYMSXP g0c0 [MARK,REF(62)] "a" ## @0x000000000db186f8 14 REALSXP g0c3 [REF(1)] (len=3, tl=0) 1,10,4 ## ENCLOS: ## @0x0000000005fda628 04 ENVSXP g0c0 [MARK,REF(65535),GL,gp=0x8000] <R_GlobalEnv> parent.env(amb1) ## <environment: R_GlobalEnv>
Função | Objetivo |
---|---|
globalenv() ou .GlobalEnv |
Ambiente global |
baseenv() |
Ambiente do pacote base |
emptyenv() |
Ambiente vazio |
environment() |
Ambiente corrente |
search() |
Lista o caminho de busca |
new.env() |
Criando um ambiente |
parent.env() |
Identificando o ambiente pai |
parent.frame() |
Ambiente funcional de chamada |
ls() ou ls.str() |
Descreve os objetos do ambiente |
get() |
Acessa o(s) valor(es) dos objetos de um ambiente |
exists() |
Verificando a existência de um objeto em um ambiente |
identical() |
Verificando a equivalência de ambientes |