Clear the Console and the Environment in R Studio

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

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“.

Example:
In this below screenshot, an R code is written in 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:

  1. Using rm() command
  2. Using the GUI
  • 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 work?

    • You see this brush button in 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 is shown here and you can see the environment is empty now.

My Personal Notes arrow_drop_up

Technical Content Engineer at GeeksForGeeks

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.