本文翻译自:Function to clear the console in R and RStudio
I am wondering if there is a function to clear the console in R and, in particular, RStudio I am looking for a function that I can type into the console, and not a keyboard shortcut. 我想知道R中是否有清除控制台的功能,尤其是RStudio,我在寻找可以在控制台中键入的功能,而不是键盘快捷键。
Someone has already provided such a function in this StackExchange post from 2010 . 从2010年开始,有人已经在此StackExchange帖子中提供了这样的功能。 Unfortunately, this depends on the RCom package and will not run on Mac OS X. 不幸的是,这取决于RCom软件包,无法在Mac OS X上运行。
#1楼
参考:https://stackoom.com/question/xplU/清除R和RStudio中的控制台的功能
#2楼
You may define the following function 您可以定义以下功能
clc <- function() cat(rep("\n", 50))
which you can then call as clc()
. 然后可以将其称为clc()
。
#3楼
cat("\014")
is the code to send CTRL + L to the console, and therefore will clear the screen. 是将CTRL + L发送到控制台的代码,因此将清除屏幕。
Far better than just sending a whole lot of returns. 比仅发送大量回报要好得多。
#4楼
如果使用默认的R控制台,则组合键Option + Command + L将清除控制台。
#5楼
In Ubuntu-Gnome , simply pressing CTRL + L should clear the screen. 在Ubuntu-Gnome中 ,只需按CTRL + L即可清除屏幕。
This also seems to also work well in Windows 10 and 7 and Mac OS X Sierra. 在Windows 10和7和Mac OS X Sierra中,这似乎也可以很好地工作。
#6楼
cat("\\f")
may be easier to remember than cat("\\014")
. cat("\\f")
可能比cat("\\014")
容易记住。
It works fine for me on Windows 10. 在Windows 10上对我来说效果很好。