How to Clear Console in R and RStudio

Everyone loves a clean working environment and it helps to increase productivity. This works the most especially for programmers and those that make regular use of the R or Rstudio consoles on their computers. However, a lot of lines and commands in the console can sometimes hinder productivity which is why we have assembled this guide to help you clear the console in R and RStudio.

R Console

Clear Console in R and RStudio

The process of clearing the R console is different for different operating systems and versions which is why we have compiled a solution for all of them. Follow the solution which best suits you to clear the console in R.

For Windows Users

If you are using R on Windows, your work is cut out for you. Clearing the console is very easy and can be done in just a few steps. There are two methods to clear the console in Windows and both of them are listed below.

1. Through Button Combination

  1. In R, press the “Ctrl” + “L” keys simultaneously.
  2. The screen will now be refreshed and the console should be cleared.

2. Through Function

You can also install a function to help clear the console for you. In order to do that:

  1. Use the following function to clear the console in R.
    cls <- function() {
           require(rcom)
           wsh <- comCreateObject("Wscript.Shell")
           comInvoke(wsh, "SendKeys", "\014")
           invisible(wsh)
    }
    cls()
  2. If you are using “R Gui” you can use the following function as well.
    cls <- function() {
    if (.Platform$GUI[1] != "Rgui")
    return(invisible(FALSE))
    if (!require(rcom, quietly = TRUE)) # Not shown any way!
    stop("Package rcom is required for 'cls()'")
    wsh <- comCreateObject("Wscript.Shell")
    if (is.null(wsh)) {
        return(invisible(FALSE))
    } else {
    comInvoke(wsh, "SendKeys", "\014")
        return(invisible(TRUE))
    }
    }
    cls()
  3. Your console will be cleared once you call these functions.

For Mac Users

Mac users can use both scripts and the key combinations to clear the console. We have listed both of them to assist them in this task.

1. Through Key Combination

It is very easy to get around this problem by using a key combination to clear your console. In order to do that:

  1. In R, press the “Option” + “Command” + “L” keys to simultaneously.
  2. This will clear the console and allow you to work more fluently.

2. Through Script

A Git hub user developed a script to allow you to easily get around this problem. You can download the script from here and follow the instructions that come with it to easily fix this issue on your console.

Kevin Arrows


Kevin is a dynamic and self-motivated information technology professional, with a Thorough knowledge of all facets pertaining to network infrastructure design, implementation and administration. Superior record of delivering simultaneous large-scale mission critical projects on time and under budget.

Expert Tip

How to Clear Console in R and RStudio

If the issue is with your Computer or a Laptop you should try using Reimage Plus which can scan the repositories and replace corrupt and missing files. This works in most cases, where the issue is originated due to a system corruption. You can download Reimage by clicking the Download button below.

Download Now

I'm not interested

Close