[Rd] unloadNamespace inside .Last.lib

Benjamin Tyner btyner at gmail.com
Thu Sep 28 15:15:46 CEST 2006


In my package's zzz.R, I put

.Last.lib <- function(libpath) {
    unloadNamespace("mypackage")
}

and I exported .Last.lib in NAMESPACE, with the intent that detaching 
the package would also cause the name space to be unloaded. However, the 
result of detach("package:mypackage") is then

Error: evaluation nested too deeply: infinite recursion / 
options(expressions=)?<environment: namespace:mypackage>
<environment: namespace:mypackage>
Error in library.dynam.unload("mypackage", libpath) :
        shared library 'mypackage' was not loaded
Error in as.character(<environment>) : cannot coerce to vector
Error in unregisterNamespace(nsname) : name space not registered
<environment: namespace:mypackage>
Error in library.dynam.unload("mypackage", libpath) :
        shared library 'mypackage' was not loaded
Error in as.character(<environment>) : cannot coerce to vector
Error in unregisterNamespace(nsname) : name space not registered
<environment: namespace:mypackage>
Error in library.dynam.unload("mypackage", libpath) :
        shared library 'mypackage' was not loaded
Error in as.character(<environment>) : cannot coerce to vector
Error in unregisterNamespace(nsname) : name space not registered
<environment: namespace:mypackage>
Error in library.dynam.unload("mypackage", libpath) :
        shared library 'mypackage' was not loaded
Error in as.character(<environment>) : cannot coerce to vector
Error in unregisterNamespace(nsname) : name space not registered
<environment: namespace:mypackage>
Error in library.dynam.unload("mypackage", libpath) :
        shared library 'mypackage' was not loaded
Error in as.character(<environment>) : cannot coerce to vector
Error in unregisterNamespace(nsname) : name space not registered
<environment: namespace:mypackage>
Error in library.dynam.unload("mypackage", libpath) :
        shared library 'mypackage' was not loaded
Error in as.character(<environment>) : cannot coerce to vector
Error in unregisterNamespace(nsname) : name space not registered
<environment: namespace:mypackage>
Error in library.dynam.unload("mypackage", libpath) :
        shared library 'mypackage' was not loaded
Error in as.character(<environment>) : cannot coerce to vector
Error in unregisterNamespace(nsname) : name space not registered
Error in detach(pos) : detaching "package:base" is not allowed
Error in detach(pos) : detaching "package:base" is not allowed
Error in detach(pos) : detaching "package:base" is not allowed


With a hundred more or so of the last error. What is the correct way (if 
any) to unload a name space using detach() alone ?

Thanks,
Ben




More information about the R-devel mailing list