我已经看过这个了,但是无法随时找到如何去做。我试图写出一些失败并显示以下错误的函数:
unloadNamespace(x)中的错误: 名称空间“图形”是由“此处的统计信息和其他包”导入的
但是,其中许多软件包甚至都没有出现在class TV extends Item implements Activable {
public void acceptWatch(Game g) {
//this works if watchVisit take a "TV" but not if it's a "Activable"
g.watchVisit(this);
}
public void watch() {
...
}
...
}
列表中。
search
这是我正在玩的功能:
[1] ".GlobalEnv" "tools:rstudio" "package:grDevices" "package:utils" "package:datasets"
[6] "package:methods" "Autoloads" "package:base"
无效的变体:
lapply(gsub("package:","",search()[grep(".*(?<=package:)",search(),perl = T)]),
function(x) unloadNamespace(x))
问题: 我怎样才能最好地卸载几个软件包(最好是全部卸载)?
答案 0 :(得分:1)
我通常运行这样的命令来卸载所有非基本软件包:
detachAllPackages <- function() {
basic.packages.blank <- c(
"stats",
"graphics",
"grDevices",
"utils",
"datasets",
"methods",
"base"
)
basic.packages <- paste("package:", basic.packages.blank, sep = "")
package.list <- search()[ifelse(unlist(gregexpr("package:", search())) == 1, TRUE, FALSE)]
package.list <- setdiff(package.list, basic.packages)
if (length(package.list) > 0) {
for (package in package.list) {
detach(package, character.only = TRUE)
}
}
}
detachAllPackages()
答案 1 :(得分:1)
卸载所有非基本软件包的简单解决方案:
lapply(names(sessionInfo()$otherPkgs), function(pkgs)
detach(
paste0('package:', pkgs),
character.only = T,
unload = T,
force = T
))