[Rd] [patch] giving library() a 'version' argument
proebuck at mdanderson.org
Thu Apr 12 21:17:45 CEST 2012
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
> 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
> 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
> 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...
More information about the R-devel