The console in R clears with a single command or keyboard shortcut
The console in R is where you type commands and see results printed back. Over time, it fills with old output that makes it harder to read what you are working on now. You can clear everything on screen with the command cat("\014"), or use the keyboard shortcut Ctrl+L on Windows and Linux, or Command+L on Mac. Both methods do the same thing: they remove all the text from view without affecting any of the data or variables you have loaded into memory.
Clearing the console is purely visual. Your variables, datasets, and functions stay exactly where they are. You are only wiping the display clean so you can see your current work without scrolling past dozens of earlier commands and their output.
Key Takeaways
- Type cat("\014") to clear the console, or press Ctrl+L (Windows/Linux) or Command+L (Mac) for the same result.
- Clearing the console removes only what you see on screen, not the data or variables stored in your R environment.
- RStudio has a broom icon in the console pane that clears the display without typing a command.
- Clearing the console is useful when you have run many commands and want a fresh view, but it does not reset your workspace.
Using the cat() command to clear the console
The most portable way to clear the console in R is the command cat("\014"). The \014 is an escape sequence that tells R to send a "form feed" character to the console, which clears the screen on almost every system where R runs. Type it exactly as shown, press Enter, and the console empties.
This command works the same way in base R, RStudio, R on Windows, R on Mac, and R on Linux. If you write a script that other people will run, using cat("\014") is safer than keyboard shortcuts because not every system interprets keyboard shortcuts the same way.
Keyboard shortcuts for faster clearing
If you are working interactively and want to clear the console without typing, use Ctrl+L on Windows or Linux, or Command+L on Mac. These shortcuts are faster than typing the command, but they only work when you are typing directly into the console—not in a script file.
RStudio also puts a broom icon in the top right corner of the console pane. Click it and the console clears when ready. This is the easiest method if you use RStudio, because you do not have to remember a command or keyboard combination.
What happens to your data when you clear the console
Clearing the console does not touch anything in your environment. If you have loaded a dataset called mydata, created variables, or written functions, they all remain in memory and ready to use. The console is just a window into your workspace—clearing it is like closing a book and opening it to a fresh page. The book's contents have not changed.
If you want to actually remove variables and start fresh, you use rm() to delete specific objects, or rm(list=ls()) to clear everything from your environment. That is different from clearing the console display.
When to clear the console during your work
Clear the console whenever the screen becomes cluttered and hard to read. This often happens after you have run many exploratory commands, tested functions, or debugged code. A clean console makes it easier to spot the output from your current command and catch errors.
Some people clear the console at the start of a new task within the same R session, just to separate their work visually. Others clear it before running a final script so they can see all the output without old results mixed in. There is no rule—it is purely about what helps you work more clearly.
Clearing the console in scripts versus interactive sessions
If you are writing a script that other people will run, think twice before including cat("\014") in it. Clearing the console in the middle of a script can make it hard for someone else to see what happened earlier. Scripts are usually meant to run from start to finish with all output visible for review.
In interactive work—when you are typing commands one at a time in the console—clearing is fine and often helpful. But in a finished script, it is usually better to let the output accumulate so anyone reading it can see the full record of what the script did.
Frequently Asked Questions
Does clearing the console delete my variables?
No. Clearing the console only removes what you see on screen. All your variables, datasets, and functions stay in memory. If you want to delete variables, use rm(variable_name) or rm(list=ls()) to clear the entire environment.
Why does cat("\014") work to clear the console?
The \014 is an escape sequence that sends a form feed character to the terminal. Form feed is an old printer command that meant "start a new page," and terminals interpret it as "clear the screen." It works across Windows, Mac, and Linux because it is a standard character code.
Can I clear the console automatically when I start R?
You can add cat("\014") to your .Rprofile startup file so it runs every time R starts. On most systems, this file lives in your home directory. However, many people skip this because they like to see their previous session's output when they restart.
What is the difference between clearing the console and clearing the environment?
Clearing the console removes the display of old commands and output. Clearing the environment removes the actual data and variables you have created. Use cat("\014") to clear the console, and rm(list=ls()) to clear your environment.
Does the keyboard shortcut Ctrl+L work in all versions of R?
Ctrl+L works in RStudio and most R installations on Windows and Linux. On Mac, use Command+L instead. If the shortcut does not work on your system, cat("\014") will work everywhere.