How to clear the workspace in R language?

In R language, there are several ways to clear the workspace.

  1. Clear all objects using the rm() function:
    rm(list = ls())
  2. Clear the specified object using the rm() function:

    rm(object_name)

  3. Remove the specified package using the detach() function:
    detach(package_name, unload = TRUE)
  4. Exiting the R session using q() function will allow for starting a new session with an empty workspace.

Before clearing the workspace, please make sure to save any necessary data and code to avoid losing them.

bannerAds