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:
I'd recommend reading more of the book. If I recall correctly, there are plenty of examples of when environmental variables come into play. Most notably are within the context of functions.
Honestly, my best piece of advice would be to read more of the book. However, I'd recommend switching to the newer version, it's structured a bit better. It also links to Advanced R Solutions, which has the answers to the questions in Advanced R.