Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to state explicit versions of package dependencies?

I tend to be rather explicit than implicit about the code I write. So after having managed to create my own packages, the next thing that immediately comes to my mind is how best to ensure robustness and reliability of my code. Part of that has to do with the packages my package depends on.

Actual Question

In that respect: is it possible to explicitly state which version of a package dependency is required/desired?

I'm looking for ways that don't require stating the actual path to, say, the zip file (which of course would easily be possible), but just make use of install.packages "standard behavior" of stating the package name only (possibly with some reference of the required version).

Due dilligence

I've checked Writing R Extensions to see what my options are with respect to the Depends section of the DESCRIPTION file, hoping for a similar mechanism that works for stating the required R version (e.g. R (>= 2.15.2)). But I didn't find anything similar for package dependencies:

The ‘Depends’ field gives a comma-separated list of package names which this package depends on. The package name may be optionally followed by a comment in parentheses. The comment should contain a comparison operator, whitespace and a valid version number.

You can also use the special package name ‘R’ if your package depends on a certain version of R — e.g., if the package works only with R version 2.11.0 or later, include ‘R (>= 2.11.0)’ in the ‘Depends’ field. You can also require a certain SVN revision for R-devel or R-patched, e.g. ‘R (>= 2.14.0), R (>= r56550)’ requires a version later than R-devel of late July 2011 (including released versions of 2.14.0). Both library and the R package checking facilities use this field: hence it is an error to use improper syntax or misuse the ‘Depends’ field for comments on other software that might be needed. Other dependencies (external to the R system) should be listed in the ‘SystemRequirements’ field, possibly amplified in a separate README file.

The R INSTALL facilities check if the version of R used is recent enough for the package being installed, and the list of packages which is specified will be attached (after checking version requirements) before the current package, both when library is called and when preparing for lazy-loading during installation.

Then I also had a look a install.packages and hoped for something like a version argument, but I guess there isn't.

Disclaimer

I'm perfectly aware that the goal of my questions might contrast R's philosophy of distributing and installing packages via CRAN package repositories where (at least I guess) new versions of certain packages just "overrule" previous ones and install.packages() always picks up the latest one available. It also does make a lot of sense to hide version peculiarities from the end user in order not to make things overly complex.

Yet, with respect to the goal of writing as robust code as possible, IMHO it also makes sense to state things very explicitly. Or at least to have the option to do so.

like image 803
Rappster Avatar asked Nov 07 '12 09:11

Rappster


1 Answers

You do use Depends. For example:

Depends: R (>= 2.15.0), foo (== 1.17-12)

would place a dependency on R versions greater than or equal to 2.15.0 and on package foo being equal to 1.17-12.

(At least if I have understood you correctly, that you want to state explicitly that your package works only with version x.yy-zz of package foo.)

I'm not sure how helpful this will be for end users though; you are probably going to be forcing them to maintain separate libraries of packages in order to use your package just to maintain the exact versions you stipulate.

like image 136
Gavin Simpson Avatar answered Oct 11 '22 12:10

Gavin Simpson