From btyner at gmail.com  Thu Sep 28 15:15:46 2006
From: btyner at gmail.com (Benjamin Tyner)
Date: Thu, 28 Sep 2006 09:15:46 -0400
Subject: [Rd] unloadNamespace inside .Last.lib
Message-ID: <451BCB02.6000306@stat.purdue.edu>

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




[Rd] unloadNamespace inside .Last.lib
Benjamin Tyner