您会在 R 会话之前/之后放置什么代码?

发布于 2024-09-13 02:20:57 字数 403 浏览 0 评论 0原文

R 允许我们将代码放在会话的开始/结束时运行。

您建议在那里放置哪些代码?

我知道三个有趣的例子(尽管我不知道“如何做”):

  1. 关闭 R 时保存会话历史记录
  2. 。在 R 会话开始时运行 Fortune()。
  3. 我正在考虑自动保存工作空间。但我并没有着手解决管理空间的问题(因此总会有 X 空间用于该备份)

还有更多想法吗? (或者如何实现上述想法)

ps:这是继续在 “stat.overflow”

R allows us to put code to run in the beginning/end of a session.

What codes would you suggest putting there?

I know of three interesting examples (although I don't have "how to do them" under my fingers here):

  1. Saving the session history when closing R.
  2. Running a fortune() at the beginning of an R session.
  3. I was thinking of having an automated saving of the workspace. But I didn't set on solving the issue of managing space (so there would always be X amount of space used for that backup)

Any more ideas? (or how you implement the above ideas)

p.s: this is continuing a thread started on "stat.overflow"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

听风念你 2024-09-20 02:20:57

除了 .Rprofile 之外,您还可以定义 .First.Last 函数。我通常使用 graphics.off() 来摆脱任何正在运行的图形显示,因此,在这种情况下,它应该是这样的:

.Last <- function() {
    graphics.off()
    save.image()  # optionally, you can define specific file/folder
    system(paste("cowsay", "Goodbye @ ", date()))  # if you're running GNU/Linux

并得到这样的结果:

 ___________________________________ 
< Goodbye @ Wed Aug 4 22:49:46 2010 >
 ----------------------------------- 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

然而,这并不多有用。虽然 .Rprofile 管理 R 启动,.Last 函数可以“退出时”执行各种操作...例如保存图像文件等...

Apart from .Rprofile, you could define .First and .Last functions. I usually put graphics.off() to get rid of any graphic displays running, so, in this case, it should go something like this:

.Last <- function() {
    graphics.off()
    save.image()  # optionally, you can define specific file/folder
    system(paste("cowsay", "Goodbye @ ", date()))  # if you're running GNU/Linux

and get something like this:

 ___________________________________ 
< Goodbye @ Wed Aug 4 22:49:46 2010 >
 ----------------------------------- 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

However, this ain't much useful. While .Rprofile manages R start-up, .Last function can perform various operations "on exit"... like saving image file or so...

半步萧音过轻尘 2024-09-20 02:20:57

我很确定我们之前也有过这样的问题。请参阅专家 R 用户,您的 .Rprofile 中有什么? 或更多内容一般搜索“[r[启动”或其他适当的标签。

I am pretty sure we had a question like this here before. See eg Expert R users, what's in your .Rprofile? or more generally search for "[r[ Startup" or other appropriate tags.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文