Possible to state explicit versions of package dependencies?
Asked Answered
A

1

9

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.

Ariel answered 7/11, 2012 at 9:49 Comment(0)
S
10

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.

Schumer answered 7/11, 2012 at 10:12 Comment(5)
Cool, thanks! Then I probably was just too stupid to read the manual ;-) Could you point me to the relevant section? I totally agree that this "verbose" way comes with a certain cost, but I rather consider this an additional option when things fail instead of making it the default way.Ariel
Nevermind, on a second glance I got it. Probably was just thrown off by the fact that the general way ("The package name may be optionally followed by a comment in parentheses") was not backed up by an actual example as for R (>= xyz).Ariel
Yes, it would be clearer with an example of an actual package dependency and only then going on to describe the special package name R to place a dependency on R itself.Schumer
As @hadley first pointed out to me, the fastest way to learn how to make a DESCRIPTION file is to download the source for a complicated package and copy/paste its DESCRIPTION. Also, roxygen2 helps with the collate field, and also the NAMESPACE file, which I try to avoid dealing with directly.Posthaste
What's interesting from the philosophy standpoint, is that the error when using a wrong operator states only '<=' and '>=' were possible. == is not mentioned, but works.Passivism

© 2022 - 2024 — McMap. All rights reserved.