tags:

views:

213

answers:

2

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

EDIT

Sorry i forgot to clarify I use windows. Thank you

+8  A: 

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.

gd047
A: 

I might be missing the point dramatically, but is simple system("clear") an easier approach? Of course, it can only be applied on Linux/Unix environments...

aL3xa