How TOs

How to Clear Console In R and RStudio

RStudio is an opensource Integrated Development Environment (IDE) that provides a user-friendly environment for the user to interact with the R language more rapidly. It is very similar to the RGuibut it has more dropdown menus, windows, and multiple tabs which makes it very easy and interesting to use. Working on the Rstudio console is very productive because of the variety of features offered by it but a lot of people ask how they can clear console in R.

Clearing console in R
RStudio

You can see three different windows as soon as you launch RStudio. The fourth window is not shown as default but you can open it by clicking File-> New File-> R Script. These windows are names as:

  1. Console.
  2. Workspace and History.
  3. Files, plots, packages, and help.
  4. The R script(s) and data view.

As soon as you launch RStudio, you see some information on the console. This information is given in the beginning to instruct the user if he needs help. Also, after running many commands, these commands will remain in the console. Sometimes, the user may not like previous commands appearing in the console window so, in this article, we are going to learn two different methods to clear the workspace in R.

Methods to Clear Environment in R

Fix Issue Automatically
If you want to have this issue fixed automatically on your computer and diagnose, list, and rectify any registry errors, we recommend that you try using the Restoro Repair Tool that can easily do all of this at a single click. It has been rated Great by Trustpilot so you don’t have to worry about anything.

Method 1: Clear R Console using Shortcuts

The shortest and the quickest way to clear the global environment in R is by using shortcut keys from the keyboards. Simply hit Ctrl+L on the keyboard and you will see that everything written in the console will be erased and the console will be cleared. This works with all Windows, Linux, and Mac.

Method 2: Define a Function to Clear Environment in R

There is another method to clear the screen. You can remove all objects in R by writing a function in the code.

cat("\014")
cat("\f")

Both of these functions are used to send Ctrl+L to the console which helps to clear the console.

Clearing Console

You can also use the following command to clear variables in R.

rm(list = ls())

Method 3: Customize a function to Erase R Console

If you want to define your own function to clear the console, you can easily do that. Just define it as follows and call it by typing clc().

clc <- function() cat(rep("\n", 50))

If you need any further assistance feel free to contact us here. Also, check out our Facebook page.

Back to top button
DMCA.com Protection Status