## The environment is empty because we haven't defined any objects
ls()
character(0)
## Create some objects
<- 7
x <- 8
y <- 9
z <- "bob"
name <- 38
age
## View the updated contents of the environment
ls()
[1] "age" "name" "x" "y" "z"
Every R command is executed in a particular environment. Conceptually, you can think of R environments as collections of the objects that R currently has stored in working memory. At this point, you only need to consider one of R’s several types of environment: the Global Environment.
The global environment is the highest-level environment that R maintains. This environment contains all of the objects you define in your R session. The interactions described below all interface with the global environment. The Environment tab in RStudio shows the contents of the global environment, by default.
We can use the ls()
function to list the contents of the current environment.
character(0)
## Create some objects
x <- 7
y <- 8
z <- 9
name <- "bob"
age <- 38
## View the updated contents of the environment
ls()
[1] "age" "name" "x" "y" "z"
The rm()
function will remove an object from the environment. The following code will remove x
from the environment.
ls()
function to view the contents of the environment.rm()
function to remove age
from the environment.ls()
to check your work.