Hi all, I just started learning environments in Programming. The link http://adv-r.had.co.nz/Environments.html#env-basics talks about the same. I have a below example where env e is created and then varibles are created with respect to e. Can anyone help me understand what is the need to create environment variables like this below while we can create variables without env
e <- new.env()
# the default parent provided by new.env() is environment from
# which it is called - in this case that's the global environment.
parent.env(e)
#> <environment: R_GlobalEnv>
ls(e)
#> character(0)
The easiest way to modify the bindings in an environment is to treat it like a list:
e$a <- 1
e$b <- 2
ls(e)
#> [1] "a" "b"