[Rd] how to control which version of a package library() installs?

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Apr 14 09:07:46 CEST 2007


On Fri, 13 Apr 2007, Tony Plate wrote:

> Prof Brian Ripley wrote:
>> On Fri, 13 Apr 2007, Tony Plate wrote:
>>
>>> Thank you!  I had not realized that the name space remained loaded.
>>> When I did unloadNamespace("ExamplePackage") after the detach() I got
>>> what I wanted.

Seth Falcon mentioned detach(unload=TRUE) (needs R 2.5.x, I think), but 
unloadNamespace() does detach() if needed.

>>> Maybe the following sentence might be a useful addition to the
>>> "Details" or "Notes" section of the help page for detach?:
>>>  To detach() and reattach() a package you will probably need to use
>>> unloadNamespace("somePackage") after detach("package:somePackage")
>>
>> We should try to explain this, but there is another level of complexity.
>> If a package has compiled code, unloading the namespace is unlikely to
>> unload the DLL (it would need to be done explicitly in .onUnload).
>> And even then, as I understand it there are OSes on which you cannot
>> really unload DLLs, and certainly cannot load another DLL of the same
>> name into the process: you get the previously loaded one.
>>
>> Given all the issues, I always work on the assumption that re-loading a
>> package into a R session is not going to do what I intend.
>
> Ok, but will it work for packages with pure R code? (disregarding things
> a package might do in its load hooks).

Not necessarily, because registered S3 methods are not removed.
Also, you cannot unload a name space from which there are imports in use.

Also, exported S4 methods from a name space are cached, so the S4 methods 
cache needs to be rebuilt (which would happen if the new version of the 
package had S4 methods, and is done by detach(unload=TRUE)).  However, the 
S4 story is worse: setting S4 generics in a package on an existing 
function captures the definition at package install time, so changing the 
version of one package may require others to be re-installed.  (That is 
not hypothetical: it has happened in R-devel several times in the last two 
weeks.)

I won't even start to mention versioned installs ....

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list