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

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Apr 14 00:04:00 CEST 2007


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.
>
> 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.

>
> -- Tony Plate
>
>
> Prof Brian Ripley wrote:
>> On Fri, 13 Apr 2007, Tony Plate wrote:
>> 
>>> library() seems to remember the location of a package when I give it a
>>> lib.loc, and then use that version thereafter, even if I don't supply
>> 
>> Not quite: it notices that it is loaded and does not load it again, 
>> possibly attaching the exports of a still-loaded namespace.
>> 
>>> lib.loc again.  Is there any way I can load different versions of a
>>> package in one R session? -- I don't seem to able to simply detach the
>>> package and then load a different version from a different library 
>>> location.
>> 
>> Without the output of search(), searchpath() and loadedNamespace() we 
>> cannot know what happened here.  But here is an example of my own
>> 
>>> library(Matrix, lib.loc="~/R/test26")
>> Loading required package: lattice
>>> searchpaths()
>>  [1] ".GlobalEnv"
>>  [2] "/data/gannet/ripley/R/test26/Matrix"
>>  ...
>>> detach(2)
>>> search()
>>  [1] ".GlobalEnv"        "package:lattice"   "package:stats"
>>  [4] "package:graphics"  "package:grDevices" "package:utils"
>>  [7] "package:datasets"  "package:methods"   "Autoloads"
>> [10] "package:base"
>>> library(Matrix, lib.loc="~/R/test-library")
>>> searchpaths()
>>  [1] ".GlobalEnv"
>>  [2] "/data/gannet/ripley/R/test26/Matrix"
>>  ...
>> 
>> The point is that the namespace Matrix is still loaded.
>> 
>>> detach(2)
>>> unloadNamespace("Matrix")
>>> library(Matrix, lib.loc="~/R/test-library")
>>> searchpaths()
>>  [1] ".GlobalEnv"
>>  [2] "/data/gannet/ripley/R/test-library/Matrix"
>> 
>> Might your example be similar?
>> 
>> 
>>> $ R
>>> [...startup info...]
>>> > # only version we currently know about is in the standard library
>>> > .find.package("ExamplePackage")
>>> [1] "c:/R/R-2.4.1/library/ExamplePackage"
>>> > # load a version from a different library e:/devinst
>>> > library(ExamplePackage, lib.loc="e:/devinst")
>>> > # and check we've got the right version ... yes
>>> > system.file(package="ExamplePackage")
>>> [1] "e:/devinst/ExamplePackage"
>>> > .find.package("ExamplePackage")
>>> [1] "e:/devinst/ExamplePackage"
>>> > detach(2)
>>> >
>>> > # Now I'd like to load the version in the standard library.
>>> > # .find.package() finds the version I want
>>> > .find.package("ExamplePackage")
>>> [1] "c:/R/R-2.4.1/library/ExamplePackage"
>>> > # but library() loads the same version it did before, even
>>> > # though I don't supply lib.loc, and .libPaths is untouched.
>>> > library(ExamplePackage)
>>> > system.file(package="ExamplePackage")
>>> [1] "e:/devinst/ExamplePackage"
>>> > .find.package("ExamplePackage")
>>> [1] "e:/devinst/ExamplePackage"
>>> > .libPaths()
>>> [1] "c:/R/R-2.4.1/library"
>>> > sessionInfo()
>>> R version 2.4.1 (2006-12-18)
>>> i386-pc-mingw32
>>> 
>>> locale:
>>> LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
>>> States.1252;LC_MON
>>> ETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United
>>> States.1252
>>> 
>>> 
>>> attached base packages:
>>> [1] "stats"     "graphics"  "grDevices" "utils"     "datasets"  "methods"
>>> [7] "base"
>>> 
>>> other attached packages:
>>> ExamplePackage
>>>          "1.0"
>>> >
>>> 
>>> Am I doing something wrong here?  I can't find any mention of
>>> persistence of package location in ?library.
>>> 
>>> thanks for any help or suggestions,
>>> 
>>> Tony Plate
>>> 
>>> ______________________________________________
>>> R-devel at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>> 
>> 
>

-- 
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