# 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")
1、首先,打开RStudio并创建一个新的文件脚本,[File]—[NewScript]。
2、这样就会发现前面代码在全局环境下留下的数据集是非常麻烦的。清洗方法如下:
3、首先,写入rm(A)以清除对应对象的数据(rm=remove)。
4、通过比较,可以发现前一个对象已经被清除。