Closed romainfrancois closed 10 years ago
I tried :
reg.finalizer( environment(), function(){
detach( "package:nothing" )
})
in the .onLoad
function, with no success. or perhaps the environment did not get gc'ed yet.
This seems to unload self. You need to trick it into not doing this during installation, or installation will fail:
.onAttach <- function(libname, pkgname) {
# Don't unload self when being installed - that will result in install error
if (Sys.getenv("R_INSTALL_PKG") != "nothing") {
unloadNamespace("nothing")
}
}
Actually, this code results in an error during library(nothing)
. But it works.
Update: this seems to work without errors:
.onLoad <- function(libname, pkgname){
if (Sys.getenv("R_INSTALL_PKG") == "nothing")
return()
pkgs <- setdiff(loadedNamespaces(), "base")
while (length(pkgs) > 0) {
for (pkg in pkgs) {
try(unloadNamespace(pkg), silent = TRUE)
}
pkgs <- setdiff(loadedNamespaces(), "base")
}
}
Perhaps an easier way to approach this is not loading the package at all, but instead having the package consist only of a single, non-exported function. Thus all the legwork is done with nothing:::nothing()
instead of require(nothing)
. Just an idea.
@leeper the essence of the package is that it gives meaning to the expression require(nothing)
. That's the only acceptable syntax ;)
It would be nice if
nothing
would detach itself. Not sure how to do that.