Clear/reset an RStudio session

clear(detach = TRUE)

Arguments

detach

logical. If TRUE, unload all but base packages.

Details

The clear() function:

  1. Clears the console window

  2. Deletes objects from the global environment

  3. Deletes plots and plot history from the Plots window

  4. Unloads all but base packages (unless detach=FALSE)

  5. Releases memory (garbage collection)

R scripts and Rmarkdown files are left untouched. No objects saved to disk are affected.

Note

This is a good way to start a fresh R session without having to quit and restart RStudio. Additionally, any script or Rmarkdown files remain open, the current working directory is unchanged, and you remain in any open project.

Examples

if (FALSE) { clear() }