# 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、首先需要打开R studio,新建文件脚本,【File】——【New Script】。
2、然后会发现,global environment这里之前代码留下的数据集非常麻烦,清除方法如下:
3、首先,写入 rm(A),即可清除相应object的数据(rm=remove)。
4、对比即可发现,之前的object已经被清除了。