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

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

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... mailing list Received on Thu 12 Apr 2012 - 19:20:57 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 - 12:00:45 GMT.

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

list of date sections of archive