Inspecting the environment
In R, every expression is evaluated within a specific environment. An environment is a collection of symbols and their bindings. When we bind a value to a symbol, call a function, or refer to a name, R will find the symbols in the current environment. If you type commands in the RStudio console, your commands are evaluated in the Global Environment.
For example, when we start a fresh R session in a terminal or RStudio, we start working within an empty global environment. In other words, there is no symbol defined in this environment. If we run x <- c(1, 2, 3)
, the numeric vector c(1, 2, 3)
is bound to symbol x
in the global environment. Then, the global environment has one binding that maps x
to the vector c(1, 2, 3) ...
Get Learning R Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.