【问题标题】:Refresh R console without quitting the session?在不退出会话的情况下刷新 R 控制台?
【发布时间】:2014-04-08 15:29:50
【问题描述】:

我通常整天打开 R 控制台,但有时我需要清理我的历史记录和工作区的背景,以便我可以测试函数或加载新数据。

我想知道是否有更简单的方法在 .Rprofile 中使用命令行,这样我就可以在不退出或重新启动当前会话的情况下刷新 R 控制台。

我通常为此做的是q()而不保存,然后再次启动R并清理历史记录。我想这里有人可以给我一些更好的建议。

提前致谢。

【问题讨论】:

  • 历史和测试函数有什么关系?也许您正在谈论清理工作区? rm(list = ls()) 如果你想在你的 .Rprofile 中添加一些东西来清除屏幕,cat('\014') 会解决这个问题
  • 是的,我澄清了我的问题。
  • 如何将rma<-rm(list = ls()) 的快捷方式添加到.Rprofile 以便我键入rma 将清理工作区?我试过rma<-fucntion() rm(list=ls()),还是不行。
  • rmls 查看当前环境。如果将它们放入函数中,则该函数将成为当前环境,因此您在函数中创建的任何变量都将是可移动变量,而不是工作区中的内容。您可以明确告诉rmls 使用.rma <- function() rm(list = ls(envir = .GlobalEnv), envir = .GlobalEnv) 搜索全局注意.rma 而不是rma。额外的点使函数对ls 隐藏,并且函数不会自行删除。您可以使用 ls(all = TRUE) 查看隐藏的(点)对象,如果需要,也可以将其删除。

标签: r settings


【解决方案1】:

关于历史,在 类 UNIX 系统(我的是 Debian)中,这个命令会刷新它

loadhistory("")

但是,正如 cmets 中所说,loadhistory 似乎与平台相关。

检查您的?loadhistory(如果您的平台上存在)。我的说:

There are several history mechanisms available for the different
R consoles, which work in similar but not identical ways. There
are separate versions of this help file for Unix and Windows.
The functions described here work on Unix-alikes under the
readline command-line interface but may not otherwise (for
example, in batch use or in an embedded application)

【讨论】:

  • 谢谢,我收到了错误> loadhistory("") Error in .External2(C_loadhistory, file) : 'loadhistory' is not currently implemented?
  • mmm loadhistory 似乎与平台有关...如果您能找到解决方案,请参阅您的 ?loadhistory。我说There are several history mechanisms available for the different R consoles, which work in similar but not identical ways. There are separate versions of this help file for Unix and Windows. The functions described here work on Unix-alikes under the readline command-line interface but may not otherwise (for example, in batch use or in an embedded application)
  • 我不明白为什么 -1... 因为我是 Unix 用户我无法在其他平台上尝试...毕竟编辑/合格的答案是正确的
  • 我不知道是谁做的,但我感谢你的努力 +1。
猜你喜欢
  • 2012-07-17
  • 2021-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多