Skip to content
Prev 40785 / 63424 Next

Understanding R's "Environment" concept

Here is an attempt at the general concept without getting technical.

How many people in the world answer to the name/title "Dad"?

Yet based on context we can usually tell who someone is talking about when they use "Dad".  

It is the same in programming, I may write a function which includes a variable named "length", but my function may call another function that also uses a variable named "length" which could be very different from my "length", the user that calls my function may have their own variable called "length".  How is the computer to know which "length" to use when (and not replace the user's "length" with the one in the function)?  By context of the functions, which context is called environments.  Each function has its own environment and will create and use variables within that environment without affecting variables of the same name in other environments.

Environments can be used for other things as well, but that starts getting more technical.