R语言的清屏命令

R语言的清屏命令是什么?类似于dos的cls的命令
2024-12-16 06:11:46
推荐回答(2个)
回答1:

命令代码参考如下:

# 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")

回答2:

Ctrl + L 清屏
或者菜单栏的 编辑 > 清空控制台