HOWTO · R

How to Clear the Console in R

This article introduces how to clear the R console interactively, offering keyboard shortcuts, command options, and RStudio menu methods. Learn to maintain a tidy workspace for efficient data analysis and programming in R.

On this page

When working with R, keeping your console clean and organized is essential for efficient data analysis and programming. A cluttered console can make it challenging to track outputs, debug errors, or even run new commands effectively. Fortunately, clearing the R console is a straightforward process. In this article, we will explore different methods to clear the R console interactively, ensuring you can maintain a tidy workspace.

One distinction runs through every method below: clearing the console removes displayed output. It does not delete the variables, functions, or other state in your R session — except for the last method, a third-party package that reaches into the workspace, which is why it comes with an explicit caution.

Clear the console in RStudio with a keyboard shortcut

In RStudio, the quickest way to clear the console is the keyboard shortcut: press Ctrl + L on Windows, or Command + Option + L on macOS, and the console display is cleared instantly.

Shortcuts depend on the environment, so treat this as the RStudio answer rather than a universal one: a different R console, a different platform, or a customized key binding may use another shortcut or none at all. If the shortcut does nothing in your console, use one of the command-based methods below instead.

Try cat("\014") only in consoles that support form feed

The classic R command for clearing the console sends a form-feed character:

cat("\014")

In consoles that interpret the form feed as a clear instruction — RStudio’s console among them — the displayed output disappears. Not every console honors it: in some implementations, such as a plain system console, the same command may only move the cursor or print a symbol, and the output stays. R has no built-in function that natively clears every console, which is why the remaining methods exist.

Scroll prior output out of view with blank lines

A different approach does not clear anything at all: it pushes the previous output up and out of view by printing many blank lines — 50 is usually enough. Wrapped in a small function, it becomes a reusable command:

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

Call clear_con() whenever you want a clean-looking console. Be clear about what it does: the earlier output is scrolled away, not erased — scroll back and it is still there, and nothing about the session changes. That is also its advantage: it works in practically any console, because it relies only on printing newlines.

Use an operating-system command only when the R console supports it

Some R consoles let you clear the display by sending the operating system a command that clears its screen. On Windows, that command is:

shell("cls")

On Linux or macOS, it is:

shell("clear")

Whether this works depends entirely on the console implementation and the environment it runs in — several R consoles and IDE setups do not pass the command through in a way that clears the R console display, so treat it as an option that works in some setups, not a guarantee.

Use the mise package cautiously

There is a third-party package named mise connected with this task. Unlike the methods above, it is not limited to the console display: the package also acts on workspace objects, so objects you created — variables, and depending on how it is used, functions — can be removed. That is a materially stronger effect than clearing output, and it is the reason for caution: read the documentation of the version you install before calling it, and do not run it in a session whose objects you still need.

Installation and loading are two separate commands:

install.packages("mise")
library(mise)
mise()

Before using it on real work, try it in a disposable session and confirm exactly what the installed version removes by default and which arguments it accepts; do not assume argument names or defaults from examples written for another version.

Whichever method you choose, remember the distinction from the start of this article: the shortcut, the form feed, the blank lines, and the shell command all affect only what the console shows. Only the package method touches the session itself — and none of these methods resets an R session.