[R] how to clear screen in R-console?

Philippe Grosjean phgrosjean at sciviews.org
Sun Feb 19 19:38:41 CET 2006


And here is a reworked version that checks if it is RGui, if WSH is 
started, etc. and that returns invisibly TRUE/FALSE:

# An R function to clear the screen on RGui:
cls <- function() {
	if (.Platform$GUI[1] != "Rgui")
		return(invisible(FALSE))
	if (!require(rcom, quietly = TRUE)) # Not shown any way!
		stop("Package rcom is required for 'cls()'")
	wsh <- comCreateObject("Wscript.Shell")
	if (is.null(wsh)) {
		return(invisible(FALSE))
	} else {
		comInvoke(wsh, "SendKeys", "\014")
		return(invisible(TRUE))
	}
}
#cls() # test
# If you want to make sure that it worked (well, not 100% sure, but...)
res <- cls()
if (res) cat("Console should be cleared now!\n")

Best,

Philippe Grosjean

P.S.: Gabor, I would like to include this function in the SciViews 
bundle. Would it be a problem for you?

..............................................<°}))><........
  ) ) ) ) )
( ( ( ( (    Prof. Philippe Grosjean
  ) ) ) ) )
( ( ( ( (    Numerical Ecology of Aquatic Systems
  ) ) ) ) )   Mons-Hainaut University, Pentagone (3D08)
( ( ( ( (    Academie Universitaire Wallonie-Bruxelles
  ) ) ) ) )   8, av du Champ de Mars, 7000 Mons, Belgium
( ( ( ( (
  ) ) ) ) )   phone: + 32.65.37.34.97, fax: + 32.65.37.30.54
( ( ( ( (    email: Philippe.Grosjean at umh.ac.be
  ) ) ) ) )
( ( ( ( (    web:   http://www.umh.ac.be/~econum
  ) ) ) ) )          http://www.sciviews.org
( ( ( ( (
..............................................................

Gabor Grothendieck wrote:
> Here is a version that uses rcom instead of RDCOMClient.
> This has the advantage that rcom is on CRAN.
> 
> cls <- function() {
> 	require(rcom)
> 	wsh <- comCreateObject("Wscript.Shell")
> 	comInvoke(wsh, "SendKeys", "\014")
> 	invisible(wsh)
> }
> cls() # test
> 
> On 2/17/06, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> 
>>Here is a translation of Norm Olsen's vbscript code into pure R.
>>This is intended for use with the Windows Rgui interface.
>>
>>cls <- function() {
>>       require(RDCOMClient)
>>       wsh <- COMCreate("Wscript.Shell")
>>       wsh$SendKeys("\014")
>>       invisible(wsh)
>>}
>>cls()  # invoke
>>
>>
>>
>>On 2/17/06, Marcus Leinweber <leinweber at neuro.mpg.de> wrote:
>>
>>>have already tried this?
>>>
>>>http://finzi.psych.upenn.edu/R/Rhelp02a/archive/55752.html
>>>
>>>m.
>>>
>>>
>>>
>>>>-----Original Message-----
>>>>From: r-help-bounces at stat.math.ethz.ch
>>>>[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Michael
>>>>Sent: Thursday, February 16, 2006 9:23 PM
>>>>To: Henrik Bengtsson
>>>>Cc: R-help at stat.math.ethz.ch
>>>>Subject: Re: [R] how to clear screen in R-console?
>>>>
>>>>I am actually using Rgui on Windows...
>>>>
>>>>What can I do?
>>>>
>>>>There is no way to programmatically clear screen?
>>>>
>>>
>>>______________________________________________
>>>R-help at stat.math.ethz.ch mailing list
>>>https://stat.ethz.ch/mailman/listinfo/r-help
>>>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>>>
>>
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 
>




More information about the R-help mailing list