[R] Recommended way of requiring packages of a certain version?
Allan Engelhardt
allane at cybaea.com
Fri Jul 16 09:06:53 CEST 2010
What is the recommended way of requiring a certain version when loading
a package (or, indeed, from R itself)?
Perl has the
require module version
use module version
require version
use version
constructs which is kind of what I am looking for (especially 'use'
which is evaluated at compile time), but R seems to have lost the
version= argument to require().
The best I have been able to come up with are constructs of the form
if ( utils::compareVersion(utils::packageDescription("data.table",
fields="Version"), "1.5") < 0 ) stop("Need data.table version 1.5 or later")
if ( utils::compareVersion(as.character(getRversion()), "2.11") >= 0 )
stop("Does not work yet with latest R.")
But this is tedious and error prone. I have created my own require()
function to automate this (it takes a vector of versions and a vector of
comparisons and only load the package if they are all met), but it is
non-standard and just that much harder for my colleagues to maintain.
Somebody must already have done this?
Allan
PS: Shouldn't utils::compareVersion("2.11.0", "2.11") return zero
instead of one?
More information about the R-help
mailing list