I've looked at this but couldn't readily find how to do it. I tried to write up some function that fails with the error:
Error in unloadNamespace(x) : namespace ‘graphics’ is imported by ‘stats and other packages here'
However, many of these packages are not even on the search
list.
[1] ".GlobalEnv" "tools:rstudio" "package:grDevices" "package:utils" "package:datasets"
[6] "package:methods" "Autoloads" "package:base"
This is the function I was playing with:
lapply(gsub("package:","",search()[grep(".*(?<=package:)",search(),perl = T)]),
function(x) unloadNamespace(x))
A variant that doesn't work:
lapply(gsub("package:","",search()[grep(".*(?<=package:)",search(),perl = T)]),
function(x) detach(x))
Question: How can I best unload several packages(better if I could unload them all)?