python rpy2模块:刷新全局R环境
rpy2 的文档指出 robjects.r 对象可以访问 R 全局环境。有没有办法将这个全局环境“刷新”到初始状态?
我希望能够将全局环境恢复到导入 rpy2.robjects 模块但尚未使用时的状态。通过这种方式,我不必担心长时间运行的作业的内存泄漏或其他意外的副作用。是的,刷新环境可能会引入不同类别的错误,但我相信就我而言这将是一场胜利。
The documentation for rpy2 states that the robjects.r object gives access to an R global environment. Is there a way to "refresh" this global environment to its initial state?
I would like to be able to restore the global environment to the state it was in when the rpy2.robjects module was imported but not yet used. In this manner, I don't have to worry about memory leaks on long running jobs or other unexpected side effects. Yes, refreshing the environment could introduce a different category of bug, but I believe in my case it will be a win.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从字面上理解您的问题,如果您只想清除
.GlobalEnv
,您可以用一行来完成:all.names=TRUE
位是必要的,因为普通ls()
不会返回某些对象名称。例如:Taking your question to mean literally what it says, if you just want to clear out
.GlobalEnv
, you can do that with a single line:The
all.names=TRUE
bit is necessary because some object names are not returned by vanillals()
. For example:R中只有/一个/“全局环境”;当R启动时它被初始化。正如 Josh 指出的那样,您可以清除其成员,但如果您碰巧需要它,这可能意味着您最好实例化新环境,并在它们之间切换或在不再需要时删除它们。
There is only /one/ "global environment" in R; it is initialized when R starts. You can clear out its members, as Josh points it out, but if you happen to need to it this might mean that you'd better instanciate new environments and either switch between them or delete them when no longer needed.