我有一个包含数据对象 (.rda) 的包,该包最初由另一个包创建,并且似乎引用了其原始命名空间。load()
的手册页解释:
Objects can be saved with references to namespaces, usually as part of the environment of a function or formula. As from R 3.1.0 such objects can be loaded even if the namespace is not available: it is replaced by a reference to the global environment with a warning. The warning identifies the first object with such a reference (but there may be more than one).
我需要删除此引用,因为它会导致在包检查期间抛出警告。我试过只加载和重新保存对象,但没有看到如何修改命名空间。有什么建议?
编辑:
对象是“网络”。我还没有想出另一个例子,但应该能够重现相同的例子:
install.packages('ndtv')
library(ndtv)
loadedNamespaces()
[1] "animation" "base" "datasets" "graphics"
[5] "grDevices" "methods" "ndtv" "network"
[9] "networkDynamic" "sna" "statnet.common" "stats"
[13] "tools" "utils"
data(msm.sim)
loadedNamespaces()
[1] "animation" "base" "datasets" "ergm"
[5] "graphics" "grDevices" "methods" "ndtv"
[9] "network" "networkDynamic" "sna" "statnet.common"
[13] "stats" "tools" "utils"
注意添加了“ergm”命名空间
最佳答案
我想我已经通过创建一个新的网络对象并复制 msm.sim
的每个命名元素来解决这个问题。对象转移到新对象,然后在旧对象上重新保存新对象。也许命名空间附件是由附加到 msm.sim
的函数触发的。当它是由 ergm 包生成的所以我在调用 edit()
时看不到它在对象上?一定会有更好的办法。我仍然认为,如果命名空间触发元素可以附加到一个对象上,那么应该有一个函数来列出它们是什么以及它们被附加到哪里。
关于r - 如何删除 R 中保存的 .rda 对象中的命名空间引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17665245/