如何在不重新启动R的情况下卸载软件包 [英] How to unload a package without restarting R
问题描述
我想卸载程序包而不必重新启动R(主要是因为在我尝试不同的方法时重新启动R,令人沮丧的程序包变得令人沮丧,但是可以想象,这可以在程序中使用以使用一个功能,然后使用另一个功能- -尽管名称空间引用可能是一种更好的用法).
I'd like to unload a package without having to restart R (mostly because restarting R as I try out different, conflicting packages is getting frustrating, but conceivably this could be used in a program to use one function and then another--although namespace referencing is probably a better idea for that use).
?library
没有显示任何将卸载软件包的选项.
?library
doesn't show any options that would unload a package.
有一个建议 >可以卸载程序包,但以下两种操作均失败:
There is a suggestion that detach
can unload package, but the following both fail:
detach(vegan)
detach(vegan)
中的错误:无效的name
参数
Error in
detach(vegan)
: invalidname
argument
detach("vegan")
detach("vegan")
中的错误:无效的name
参数
Error in
detach("vegan")
: invalidname
argument
那我该如何卸载包裹?
推荐答案
尝试一下(有关更多详细信息,请参见?detach
):
Try this (see ?detach
for more details):
detach("package:vegan", unload=TRUE)
有可能一次加载一个软件包的多个版本(例如,如果您在不同的库中有开发版本和稳定版本).为了确保所有副本均已分离,请使用此功能.
It is possible to have multiple versions of a package loaded at once (for example, if you have a development version and a stable version in different libraries). To guarantee that all copies are detached, use this function.
detach_package <- function(pkg, character.only = FALSE)
{
if(!character.only)
{
pkg <- deparse(substitute(pkg))
}
search_item <- paste("package", pkg, sep = ":")
while(search_item %in% search())
{
detach(search_item, unload = TRUE, character.only = TRUE)
}
}
例如,用法是
detach_package(vegan)
或
detach_package("vegan", TRUE)
这篇关于如何在不重新启动R的情况下卸载软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!