From tplate at acm.org  Sat Apr 14 00:31:25 2007
From: tplate at acm.org (Tony Plate)
Date: Fri, 13 Apr 2007 16:31:25 -0600
Subject: [Rd] how to control which version of a package library()
	installs?
In-Reply-To: <Pine.LNX.4.64.0704132252050.17244@auk.stats>
References: <461FED8C.2040603@acm.org>
	<Pine.LNX.4.64.0704132204150.18247@gannet.stats.ox.ac.uk>
	<461FFA29.8040401@acm.org>
	<Pine.LNX.4.64.0704132252050.17244@auk.stats>
Message-ID: <462004BD.60702@acm.org>

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.
>>
>> 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).  If so, then how about:

To detach() and reattach() a package in order to get a different version 
of it, it will be necessary to do unloadNamespace("somePackage") after 
detach("package:somePackage").  However, this is very likely to be 
problematic for packages with compiled code because some OSes do not 
support unloading DLLs or loading another DLL of the same name.

Or are there yet other issues?

-- Tony Plate

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



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