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.