windows 以编程方式清除 R 控制台
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2824965/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Clear R Console programmatically
提问by Brani
Possible Duplicate:
Function to Clear the Console in R
可能的重复:
在 R 中清除控制台的函数
Is there a way to invoke the Clear Console (Ctrl+L) menu command programmatically?
有没有办法以编程方式调用 Clear Console ( Ctrl+ L) 菜单命令?
回答by George Dontas
I use a function for doing that, and actually have put it in {R directory}\etc\Rprofile.site so that it will always be available for use.
我使用一个函数来做这件事,实际上已经把它放在 {R directory}\etc\Rprofile.site 中,这样它就可以一直使用。
cls <- function() {
require(rcom)
wsh <- comCreateObject("Wscript.Shell")
comInvoke(wsh, "SendKeys", "4")
invisible(wsh)
}
cls()
To clear the console give
清除控制台给
cls()
P.S. The function doesn't work the first time it's called and that's why I invoke the function immediately after declaring it in Rprofile.site. As I recall, you may be asked to install some program, in order for this to work.
PS 该函数在第一次被调用时不起作用,这就是为什么我在 Rprofile.site 中声明它后立即调用该函数。我记得,您可能会被要求安装一些程序,以使其正常工作。
回答by Contango
Create this function:
创建这个函数:
cls <- function() cat(rep("\n",100))
Then call it:
然后调用它:
cls()
Works with:
适用于:
- Windows
- Linux
- Mac
- 视窗
- Linux
- 苹果电脑
回答by aL3xa
I might be missing the point dramatically, but is simple system("clear")
an easier approach? Of course, it can only be applied on Linux/Unix environments...
我可能会大大错过这一点,但是简单system("clear")
的方法更简单吗?当然,它只能应用于Linux/Unix环境……