r - 如何从 R 中的特定包中分离所有对象和方法?

标签 r methods environment-variables s4

<分区>

我需要在一个 R session 中加载和分离大量包(我正在查看哪些函数是跨不同包的方法)。 detach() 对我想要的不起作用,因为它不会从环境中删除所有内容;例如,如果你运行:

require(pomp)
detach('package:pomp', character.only = TRUE)
print(methods('show'))

show,pomp.fun-method 仍然在列表中,这不是基础 R 中存在的方法。如何删除与关联的所有 方法和对象一袋?或者,有没有办法在 R 中创建一个临时环境来加载包,然后我可以销毁它以删除包中方法中的所有对象?

最佳答案

要尝试卸载在加载包时加载的命名空间,您必须在 detach() 中设置参数 unload = TRUE

在你的例子中:

detach('package:pomp', unload = TRUE, character.only = TRUE)

但是,如果您阅读了文档中的详细信息 (?detach),则需要注意一些事项:

If a package has a namespace, detaching it does not by default unload the namespace (and may not even with unload = TRUE), and detaching will not in general unload any dynamically loaded compiled code (DLLs). Further, registered S3 methods from the namespace will not be removed. If you use library on a package whose namespace is loaded, it attaches the exports of the already loaded namespace. So detaching and re-attaching a package may not refresh some or all components of the package, and is inadvisable.

强调我的。请注意它可能并不总是有效。

关于r - 如何从 R 中的特定包中分离所有对象和方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34213882/

相关文章:

r - R 中的 write.csv 将我的日期转换为 10 位整数

node.js - 当变量在服务器上定义时,Meteor.call 返回 'undefined' 结果

ruby-on-rails - 创建一个像 Devise 的 current_user 一样的方法以在任何地方使用

r - 如何判断下标是否越界?

mysql - 对数据框应用函数返回不正确的结果

r - 将回归模型估计值合并到一个表中

java - Java中如何处理对象中的 float ?

environment-variables - 带有 Pinia 的 Nuxt 3 中的环境变量

c++ - x64 位 Windows 上的 ExpandEnvironmentStrings( ... ) 正在将 %programfiles% 扩展到 x86 路径

python - 使用 Airflow 在运行时导出环境变量