命令代码参考如下:
# 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")
Ctrl + L 清屏
或者菜单栏的 编辑 > 清空控制台