22

Possible Duplicate:
Function to Clear the Console in R

In bash, its like this:

$ clear

And I believe it's CTL-L in the Windows version of R. But how do you clear the R console in Unix-type R Consoles? Do you need to write a special function and what would that look like?

Community
  • 1
  • 1
Milktrader
  • 9,278
  • 12
  • 51
  • 69

5 Answers5

44

Command+Option+L in R for Mac OS X

Ctrl+L in RStudio for Mac OS X

Community
  • 1
  • 1
Alex
  • 64,178
  • 48
  • 151
  • 180
  • 3
    Here's a handy tip for finding any menu command in OS X: cmd-shift-/ to bring up the Help menu, type "clear", see where the relevant menu items are. – Daniel Dickison Nov 05 '10 at 02:02
16

Since you ask for Ubuntu as well, it's simply Ctrl-L from a standard gnome-terminal.

nbro
  • 15,395
  • 32
  • 113
  • 196
chrisamiller
  • 2,712
  • 2
  • 20
  • 25
10

I discovered that you call also type unix commands with the system() function.

system('clear')
Milktrader
  • 9,278
  • 12
  • 51
  • 69
6

For what it's worth, my console to R is provided by ESS on whichever platform I use -- and as that is within Emacs, it is always Ctrl-l (or C-l in the common shorthand for Emacs).

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
2

Create this function:

cls <- function() cat(rep("\n",100))

Then call it:

cls()

Compatible with Windows, Linux and Mac.

Contango
  • 76,540
  • 58
  • 260
  • 305
  • 2
    insert 100 newlines == clear? false – vol7ron Jul 22 '13 at 18:36
  • 1
    There is a much better way to do this. Rather than put 100 new lines, which is not really a clear, you can also print out the code for cntl-L. – Justace Clutter Nov 03 '15 at 12:52
  • 1
    if you wanna get fancy: `clear <- function() { cat(rep("\n", Sys.getenv("LINES"))); }`. But, yeah, while not a true "clear-screen," it does clear the screen and add a useful bit of space between code segments. – Sam Jan 25 '17 at 19:44