How to clear the R environment

As a few people have already mentioned, to clear your global workspace, you can use

rm(list = ls())

However, I would suggest if you are using this regularly, you are probably doing it wrong. Instead, I would change the settings to never save your workspace. You can do this in RStudio

This means when you restart R via Ctrl+Shift+F10, your workspace is cleared.


Under Linux, I use the following alias when accessing R via the command line:

alias R="R --no-save --no-restore-data --quiet"
11 Likes