Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear R Console programmatically [duplicate]

Tags:

windows

r

Possible Duplicate:
Function to Clear the Console in R

Is there a way to invoke the Clear Console (Ctrl+L) menu command programmatically?

like image 672
Brani Avatar asked May 13 '10 07:05

Brani


2 Answers

I use a function for doing that, and actually have put it in {R directory}\etc\Rprofile.site so that it will always be available for use.

cls <- function() {
        require(rcom)
        wsh <- comCreateObject("Wscript.Shell")
        comInvoke(wsh, "SendKeys", "\014")
        invisible(wsh)
 }
cls()

To clear the console give

cls()

P.S. The function doesn't work the first time it's called and that's why I invoke the function immediately after declaring it in Rprofile.site. As I recall, you may be asked to install some program, in order for this to work.

like image 187
George Dontas Avatar answered Nov 08 '22 22:11

George Dontas


Create this function:

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

Then call it:

cls()

Works with:

  • Windows
  • Linux
  • Mac
like image 36
Contango Avatar answered Nov 08 '22 22:11

Contango