Henrik Bengtsson
2002-Jan-24 23:52 UTC
Best way to check/assert a certain version of [R] or a package
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. 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"? 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? Thanks a lot Henrik Bengtsson Dept. of Mathematical Statistics @ Centre for Mathematical Sciences Lund Institute of Technology/Lund University, Sweden (+2h UTC) Office: P316, +46 46 222 9611 (phone), +46 46 222 4623 (fax) h b @ m a t h s . l t h . s e http://www.maths.lth.se/matstat/staff/hb/ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Thomas Lumley
2002-Jan-25 01:23 UTC
Best way to check/assert a certain version of [R] or a package
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Prof Brian Ripley
2002-Jan-25 12:16 UTC
Best way to check/assert a certain version of [R] or a package
On Fri, 25 Jan 2002, Henrik Bengtsson wrote: [...]> 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?Take a look at packageStatus, which uses package.description and compareVersion. package.dependencies can be used to test the R version at present, at least. -- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Henrik Bengtsson
2002-Jan-25 13:43 UTC
SUMMARY: Best way to check/assert a certain version of [R] or a package
Thanks for all you replies here. Here is a short summary how to solve the two problems discussed: 1) Check for correct version of [R] current <- paste(R.Version()[c("major", "minor")], collapse=".") wanted <- "1.4.0" tooOld <- (compareVersion(current, wanted) < 0) 2) Check for correct version of a package package <- "eda" current <- package.description(package)["Version"] wanted <- "1.3.1" tooOld <- (compareVersion(current, wanted) < 0) It could be questioned if compareVersion("1.4.0", "1.4") should give 1 and not 0, but hopefully that is not an real issue. PS. packageStatus() seems promising. DS. Have nice day! Henrik Bengtsson Dept. of Mathematical Statistics @ Centre for Mathematical Sciences Lund Institute of Technology/Lund University, Sweden (+2h UTC) Office: P316, +46 46 222 9611 (phone), +46 46 222 4623 (fax) h b @ m a t h s . l t h . s e http://www.maths.lth.se/matstat/staff/hb/ On Fri, 25 Jan 2002, Prof Brian Ripley wrote:> On Fri, 25 Jan 2002, Henrik Bengtsson wrote: > > [...] > > > 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? > > Take a look at packageStatus, which uses package.description and > compareVersion. package.dependencies can be used to test the R version > at present, at least. > > -- > 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._