Skip to content
Prev 86795 / 398502 Next

how to clear screen in R-console?

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: