Best way to check/assert a certain version of [R] or a package
Prof Brian D Ripley
ripley at stats.ox.ac.uk
Fri Jan 25 09:21:52 CET 2002
On Thu, 24 Jan 2002, Thomas Lumley wrote:
> 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'
I don't think it is sufficient, and have been about to propose automatic
run-time R version checking. The problem is that if installed on one
version it can be used on another. It's a particular problem with binary
distributions.
> > 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
Yes, but for checking R versions that does not arise.
R.Version()$major == 1 && R.Version()$minor >= 4.1
will work (and normally >= 4 is the sort of test required).
> > 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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