Best way to check/assert a certain version of [R] or a package

Thomas Lumley tlumley at u.washington.edu
Fri Jan 25 02:23:21 CET 2002


On Fri, 25 Jan 2002, Henrik Bengtsson wrote:

> When loading a package with library(APkg) or require(APkg) I would like to
> make sure that (1) the correct version of [R] is installed. If not an
> informative error message should be given. I would also like to make sure
> that (2)  another required package which is loaded from within the APkg
> package (by require(OtherPkg)) is of a certain version or later.

Following my usual habit of answering a different question from the one
you asked: there is an automated way to do this at install-time, which
should be sufficient for requiring 'at least' a certain version.  The `Depends'
field in the DESCRIPTION is described in `Writing R Extensions'

> First of all, I believe that the check should be done in .First.lib(),
> correct? To check for the correct version of [R] I would guess that
> R.Version()$major and R.Version()$minor could be used to retrieve the
> version. Is there any prewritten function to compare two version strings;
> "1.2.1" is before "1.2.10"?

 No, but you can convert it to a vector of numbers with
eg as.numeric(strsplit("1.2.10","\\.")[[1]])
and compare the resulting numbers

> What is the easiest way to retrieve the version string of a certain package.
> Should one find the path to the package, then load the DESCRIPTION file and
> parse it?

eg
> read.dcf(file = system.file("DESCRIPTION",package="MASS"),fields="Version")
     Version
[1,] "6.3-2"


	-thomas


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list