From tplate at acm.org  Fri Apr 13 23:46:17 2007
From: tplate at acm.org (Tony Plate)
Date: Fri, 13 Apr 2007 15:46:17 -0600
Subject: [Rd] how to control which version of a package library()
	installs?
In-Reply-To: <Pine.LNX.4.64.0704132204150.18247@gannet.stats.ox.ac.uk>
References: <461FED8C.2040603@acm.org>
	<Pine.LNX.4.64.0704132204150.18247@gannet.stats.ox.ac.uk>
Message-ID: <461FFA29.8040401@acm.org>

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

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