▷ How to clean the console in R and RStudio

Contents

Everyone likes a clean work environment and that helps increase productivity. This works especially for programmers and those who make regular use of R or Rstudio consoles on their computers.. Despite this, too many lines and commands on the console can sometimes hamper productivity, so we have put together this guide to help you clean the console in R and RStudio.

rconsole-6133405Console R

Delete console in R and RStudio

The R console cleaning procedure is different for different operating systems and versions, so we have compiled a solution for all of them. Follow the answer that suits you best to clean the console in R.

For Windows users

If you use R in Windows, your work is done for you. Cleaning the console is very easy and can be done in just a few steps. There are two methods to clean the console in Windows and both are listed below.

1. Via button combination

  1. In the R, press the keys “Ctrl” + “L” simultaneously.

  2. The screen will now refresh and the console should clear.

2. Through function

You can also install a feature to help you clean the console. For this:

  1. Use the next function to remove the console in R.

    cls <- function() {
           require(rcom)
           wsh <- comCreateObject("Wscript.Shell")
           comInvoke(wsh, "SendKeys", "14")
           invisible(wsh)
    }
    cls()
  2. If you are using »R Gui», you can also use the next function.

    cls <- function() {
    and (.Platform$GUI[1] != "rgi")
    return(invisible(FAKE))
    and (!require(rcom, silently = TRUE)) # Not shown in any way!
    stop("Rcom package is required for $ 0027cls()$0027")
    wsh <- comCreateObject("Wscript.Shell")
    and (it.null(wsh)) {
        return(invisible(FAKE))
    } more {
    comInvoke(wsh, "SendKeys", "14")
        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 key combinations to clean up the console. We have listed both to help you in this task.

1. Through the key combination

It is very easy to avoid this problem by using a combination of keys to clean the console. To do that:

  1. In the R, press the keys “Option” + “Command” + “L” stops simultaneously.

  2. This will clean the console and allow you to work more fluently.

2. Via script

A user at the Git center developed a script so that he could easily fix this problem. You can download the script from here and follow the accompanying instructions to easily fix this problem on your console.

Subscribe to our Newsletter

We will not send you SPAM mail. We hate it as much as you.