Why environment variable are created

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.
#> <environment: R_GlobalEnv>
#> 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
#> [1] "a" "b"

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.

Thanks, Can you suggest some thing related to this :slight_smile:

Can you suggest some thing related to this

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.

Thanks a lot ...............

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.