[Rd] [patch] giving library() a 'version' argument
Martin Maechler
maechler at stat.math.ethz.ch
Fri Apr 13 10:52:30 CEST 2012
>>>>> Roebuck,Paul L <proebuck at mdanderson.org>
>>>>> on Thu, 12 Apr 2012 14:17:45 -0500 writes:
> On 4/12/12 1:56 PM, "Ken Williams" <Ken.Williams at windlogics.com> wrote:
>> On April 12, 2012 1:48 PM, Paul Roebuck wrote:
>>
>>> Not sure I follow you here. The packageVersion() method is
>>> essentially a shortcut to packageDescription("MyPackage")$Version. I
>>> generally avoid doing package upgrades in my scripts so the loaded
>>> package IS the installed package (even when playing .libPaths()
>>> tricks).
>>
>> The scenario is:
>>
>> library(PackageX) # Quietly loads version 1 of PackageY
>>
>> # Try to load a specific version of PackageY
>> .libPaths('directory/containing/PackageY/version-2') library(PackageY)
>> # actually does nothing, since it's already loaded
>> stopifnot(packageVersion('PackageY') >= 2) # ??
>>
>>
>> The intention of the stopifnot() expression is to make sure version 2
>> is loaded.
>>
>> If packageVersion() goes & looks for PackageY in .libPaths() even when
>> the package is already loaded, it will provide the wrong answer -
>> because it will find version 2, but version 1 is what's loaded.
>> However, if packageVersion() checks the version of what's already
>> loaded, then it would do the right thing here.
>>
>> I don't think the docs for packageDescription() clarify what happens
>> in this case, but I could be missing it.
> If you're going to "play" with .libPaths() like that,
> it should be done prior to ANY libraries being loaded.
> Going about the style you do below, you'd need to parse
> sessionInfo() instead. packageVersion() as well as
> packageDescription() give you the information based on
> the first package in the path with the same name. If you
> dynamically change the path, the returned information
> could be different...
Aa..h, now we are getting into a more interesting issue:
Fortunately, what you say above has *not* been true for a while
(I think, but am not sure, that I was involved in fixing it..):
Indeed nowadays, packageDescription() *) *does*
use the correct package version, by inspecting the "path"
attribute of the package, in the same way as
searchpaths()
does --- a function, BTW, that I think should be known and used
more than I think it is.
*) packageVersion() is built on packageDescription() and hence
is also correct accordingly.
--
Martin Maechler, ETH Zurich (and R core).
More information about the R-devel
mailing list