## The environment is empty because we haven't defined any objects
ls()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"
This page is a bonus topic. You don’t need to master environments to move on to the next tutorial on R Functions.
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.You’re ready to move on to R Functions if you can:
If any of these still feel shaky, that’s completely fine, revisit the relevant page above before continuing, or try the Knowledge Quiz to see exactly where to focus.