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?

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to