Hi Allan,

When you create an R package you can specify in the DESCRIPTION file that your package depends on a certain R version and versions of packages. For example:

Package: automap
Version: 1.0-7
Date: 2010/05/04
Title: Automatic interpolation package
Author: Paul Hiemstra <p.hiems...@geo.uu.nl>
Maintainer: Paul Hiemstra <p.hiems...@geo.uu.nl>
Description: This package performs an automatic interpolation by automatically estimating the variogram and then calling gstat.
Depends: R (>= 2.7.0), methods, sp (>= 0.9-4), gstat (>= 0.9-58)
Imports: lattice
License: GPL

So distributing code to other people is preferably done using R packages, which gives you this option.

regards,
Paul

On 07/16/2010 09:06 AM, Allan Engelhardt wrote:
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.


--
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +3130 253 5773
http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770

______________________________________________
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