以编程方式清除 R 控制台 [英] Clear R Console programmatically

查看:44
本文介绍了以编程方式清除 R 控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
R 中清除控制台的功能

有没有办法以编程方式调用清除控制台 (Ctrl+L) 菜单命令?

Is there a way to invoke the Clear Console (Ctrl+L) menu command programmatically?

推荐答案

我使用了一个函数来做这件事,实际上已经把它放在 {R directory}\etc\Rprofile.site 中,以便它始终可用.

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.

cls <- function() {
        require(rcom)
        wsh <- comCreateObject("Wscript.Shell")
        comInvoke(wsh, "SendKeys", "\014")
        invisible(wsh)
 }
cls()

清除控制台给

cls()

附言该函数在第一次被调用时不起作用,这就是为什么我在 Rprofile.site 中声明它后立即调用该函数.我记得,您可能会被要求安装一些程序,以使其正常工作.

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.

这篇关于以编程方式清除 R 控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆