Overview - Environment and closures
What is it?
In R, an environment is a place where variables and their values live. A closure is a function that remembers the environment where it was created, even if called somewhere else. This means the function can access variables from that environment later. Together, environments and closures let R keep track of data and functions in a flexible way.
Why it matters
Without environments and closures, R would not be able to keep track of variables inside functions or remember values after a function finishes. This would make it hard to write reusable and safe code. Closures let you create functions that carry their own data, which is powerful for building complex programs and packages.
Where it fits
Before learning environments and closures, you should understand basic R functions and variables. After this, you can explore advanced topics like functional programming, lexical scoping, and package development.