[R] clear screen?

Gabor Grothendieck ggrothendieck at gmail.com
Mon May 4 13:36:27 CEST 2009


On Mon, May 4, 2009 at 6:50 AM, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
> On 03/05/2009 6:50 PM, Charles Annis, P.E. wrote:
>>
>> I’ve been using this routine for several years.  I’m sorry, I don’t
>> remember
>> where I got it.  It works as it should, viz. it blanks the R console.  But
>> it requires package rcom and now that requires rscproxy.
>>
>> cls <-
>> function () {
>>    require(rcom)
>>    wsh <- comCreateObject("Wscript.Shell")
>>    comInvoke(wsh, "SendKeys", "\f")
>>    invisible(wsh)
>> }
>>
>>> cls()
>>
>> Loading required package: rcom
>> Loading required package: rscproxy
>>
>> This seems like overkill to me just to blank the R console, especially
>> since
>> I am trying to diminish the number of necessary packages to support my
>> home-brew package.
>>
>> So, is there an easier way to blank the R console in Windows?
>
> Ctrl-L will do it.  If you want to put it in a function, I don't think so.
>
> An item that has been on my wish list for a long time is to rewrite the menu
> system in the Windows gui so that all items can be invoked from R code.
>  It's been sitting there in the section entitled "I wish someone else would
> do this."  It would not be hard, but it would be a lot of tedious work.

Note that the same technique used to clear the screen could be used for
this as well. For example, this causes the FAQ to appear by sending
the appropriate set of characters to active the menu:

sendKeys <- function (x) {
	require(RDCOMClient)
	wsh <- COMCreate("Wscript.Shell")
	wsh$SendKeys(x)
	invisible(wsh)
}
faq <- function() sendKeys("%HF\n")

faq()

Might have to add some Sys.sleep calls to slow it down but so far it
seems to work for me.




More information about the R-help mailing list