Skip to content

Latest commit

 

History

History
42 lines (30 loc) · 1.32 KB

GlobalEnvironment.md

File metadata and controls

42 lines (30 loc) · 1.32 KB

Global Environment

An environment in R is container in which objects (data/values) are bound to names, i.e. variables. So it stores variables.

Environments are used throughout the R language. There is the global environment, i.e., your work space in which assignments made at the prompt are stored.

We can list the contents of an environment with the ls() command. This gives us the names of the variables in that environment. If some of the names start with a ., use

ls(all = TRUE)

Packages

Environments are used to store the functions and data in an R package that is loaded.

Call Frames

Environments are also used to represent call frames, i.e., a call to a function. The call frame is an environment, and stores the values for the parameters and any local variables created within the body of that function call.

Later we'll talk more about packages and how they find symbols to which they refer.

Mutable & Pass-by-reference

Environments have a particular property that makes them somewhat unique as R data structures. They are mutable, i.e. passed by reference. If we pass an environment in a function call, that function can change the contents of the environment and the caller will see those changes when they are made and when the function returns. This is not true of the common data structures in R.