Open In App
Related Articles

Clear the Console and the Environment in R Studio

Like Article
Save Article
Report issue

R Studio is an integrated development environment(IDE) for R. IDE is a GUI, where you can write your quotes, see the results and also see the variables that are generated during the course of programming.

Clearing the Console

We Clear console in R and RStudio, In some cases when you run the codes using “source” and “source with echo” your console will become messy. And it is needed to clear the console. So let’s now look at how to clear the console. The console can be cleared using the shortcut key “ctrl + L“. 


In this below screenshot, an R code is written in the script tab defined a and calculated b and printed a, b. When this code is executed using “source with echo” all the commands will get printed in the console tab. Now, to clear this console click on the console tab and enter the key combination “ctrl + L“. Once it is done the console will get cleared.

Note: Remember that clearing the console will not delete the variables that are there in the workspace. You can see that in the environment tab even though we have cleared the console in the workspace we still have the variables that are created earlier.

Clearing the Environment

Variables on the R environment can be cleared in two ways:

Using rm() command:

When you want to clear a single variable from the R environment you can use the “rm()” command followed by the variable you want to remove.

-> rm(variable) 

variable: that variable name you want to remove. 

If you want to delete all the variables that are there in the environment what you can do is you can use the “rm” with an argument “list” is equal to “ls” followed by a parenthesis. 

-> rm(list=ls()) 

Using the GUI: 

We can also clear all the variables in the environment using the GUI in the environment pane. 

How does it works?

You see this brush button in the environment pane.

So when you press the brush button it will pop up a window saying “you want to remove all the objects from the environment?”

And if you say yes it will clear all the variables which are shown here and you can see the environment is empty now.

Last Updated : 13 Oct, 2021
Like Article
Save Article
Share your thoughts in the comments
Similar Reads