清除R工作区中的所有用户定义对象

时间:2023-01-24 13:42:17

I'm working with Rserve via Ruby bindings. It's pretty trivial to establish a connection to Rserve, and I assume its a good idea to persist that connection globally to avoid the overhead of tearing it down and re-building it as needed (I'm not operating in a multi-threaded environment).

我正在通过Ruby绑定使用rservice。建立rservice的连接是非常简单的,我认为在全局上持久化这个连接是一个好主意,以避免在需要的时候破坏它并重新构建它(我不是在多线程环境中操作)。

Since the objects defined will stick around, and potentially class with later operations, I want to clear them out. I've seen:

因为定义的对象将会继续存在,并且有可能在以后的操作中使用类,所以我想把它们清除掉。我看过:

myvar = 1
rm(myvar)

However, I would rather re-initialize everything, to avoid having to manually keep track of whats defined. Is this possible? Is there a significant overhead associated with it if so?

但是,我宁愿重新初始化所有东西,以避免手工跟踪定义的whats。这是可能的吗?如果有的话,是否存在与之相关的重大开销?

2 个解决方案

#1


30  

it is a bit dangerous but: rm(list=ls()) really, don't do this.

这有点危险,但是:rm(list=ls())真的,不要这样做。

#2


1  

If you are working with a dataset let say named data_new, you can use the following comment to remove all information about data_new from your workspace:

如果您正在处理一个名为data_new的数据集,您可以使用以下注释从您的工作区中删除关于data_new的所有信息:

rm(data = data_new)

rm(数据= data_new)

#1


30  

it is a bit dangerous but: rm(list=ls()) really, don't do this.

这有点危险,但是:rm(list=ls())真的,不要这样做。

#2


1  

If you are working with a dataset let say named data_new, you can use the following comment to remove all information about data_new from your workspace:

如果您正在处理一个名为data_new的数据集,您可以使用以下注释从您的工作区中删除关于data_new的所有信息:

rm(data = data_new)

rm(数据= data_new)