Re: [Rd] [patch] giving library() a 'version' argument

From: Martin Maechler <>
Date: Fri, 13 Apr 2012 10:52:30 +0200

>>>>> Roebuck,Paul L <> >>>>> on Thu, 12 Apr 2012 14:17:45 -0500 writes:

    > On 4/12/12 1:56 PM, "Ken Williams" <> 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


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

______________________________________________ mailing list
Received on Fri 13 Apr 2012 - 08:54:37 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 13 Apr 2012 - 20:40:45 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive