在 R 中,我可以使用工作区保存加载的包吗?
R 通常只将对象保存在 .GlobalEnv 中:
$ R
> library(rjson)
> fromJSON
function (...) ...
> q(save='yes')
$ R
> fromJSON
Error: object 'fromJSON' not found
有没有办法也保存此信息?
R normally only saves objects in .GlobalEnv:
$ R
> library(rjson)
> fromJSON
function (...) ...
> q(save='yes')
$ R
> fromJSON
Error: object 'fromJSON' not found
Is there a way to have this information saved as well?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
现在,您可以将 R 会话信息保存到文件中并将其加载到另一个会话中。
首先安装“session”包:
加载您的库和数据,然后将会话状态保存到文件中:
然后您可以在另一个会话中加载会话状态:
参考:https://www.rdocumentation.org/packages/session/versions/1.0.3/topics/save.session
You are now able to save R session information to a file and load it in another session.
First install the "session" package:
Load your libraries and your data, then save the session state to a file:
Then you can load the session state in another session:
Reference: https://www.rdocumentation.org/packages/session/versions/1.0.3/topics/save.session
据我所知,没有。工作区用于数据和函数等对象。启动 R 并加载特定的包就是 .Rprofile 文件的用途,并且每个目录中可以有不同的文件。
我想,您可以在工作区中保存一个函数来加载所需的包,然后在第一次启动 R 时运行该函数。
To the best of my knowledge, no. The workspace is for objects like data and functions. Starting R with particular packages loaded is what your .Rprofile file is for, and you can have a different one in each directory.
You could, I suppose, save a function in the workspace that loads the packages you want, and then run that function when you first start R.
joran 是对的,但我想提一下一种技术,虽然很麻烦,但可能会有所帮助。
您可以使用检查点程序(例如 DMTCP)来保存整个 R 进程并稍后重新启动。
joran is right, but I want to mention a technique that, while cumbersome, might be helpful.
You can use a checkpointing program such as DMTCP to save the entire R process and restart it later.
我建议不要在 r 会话之间保存任何内容,而是使用代码重新创建它。这更有可能导致可重复的结果。
I'd recommend not saving anything between r sessions and instead recreate it all using code. This is much more likely to lead to reproducible results.