Reputation: 3843
In R, how to remove all of the typed commands from the command window, so that I can have a clearer working environment.
Upvotes: 7
Views: 25093
Reputation: 983
try this:
cls <- function(){
if (getIdentification() == 'R Console')
cat('\f') # R Console
else{
if (Sys.info()[['sysname']] == 'windows')
system('powershell clear-host') # Windows
else
system('clear') # *Unix
}
}
this function may works both on windows, and *Unix.
i don't have a computer runs *Unix system, if this code works on Mac or Linux, let me know.
Upvotes: 0
Reputation: 5497
As others pointed out its CTRL + L otherwise you may find this helpful if you are using Windows: function to clear screen
The functions that appear in that blog post seem to be copied (without giving attribution) from this r-help post and this r-help post.
EDIT:
Added caveat about Windows and also link to original original source.
Upvotes: 3
Reputation: 16981
In RGui, just press Ctrl+L and you should have a clean command line window.
Upvotes: 1
Reputation: 61933
On windows using RGui, a mac inside the terminal, or on Linux: Ctrl+L will clear the screen for you. You won't be able to scroll up to view what you've done in the session previously though. You can still use the up arrow to scroll through your history though.
On a mac using the gui: Option+Command+L will do the same thing as clearing in the windows gui.
On any system: You could create a function to do something similar to clearing the screen for you:
clr <- function(){cat(rep("\n", 50))}
All this does is prints enough linebreaks to essentially push everything above what is viewable on the console. You can still scroll up to view the previous output but you'll have 50 lines of whitespace. Depending on your monitor size you might need to increase the number of line breaks to clear everything.
Upvotes: 16