9 Using dependencies from R-universe
9.1 Can a CRAN package take on a dependency from R-universe?
Yes! It has to be an optional dependency (Suggests
) and you need to
List the R-universe in the
Additional_repositories
field inDESCRIPTION
. Examples of CRAN packages doing so. The field will not ensure installation of the package. Its sole purpose is allowing CRAN to check the package is indeed available in that other repository.Alternatively, if you are ok getting a NOTE from R CMD check (that you can explain in cran-comments.md) list the URL where to install the package somewhere else in
DESCRIPTION
(example).Document, for the user, how to install the missing package. You can do that
- In user-facing documentation (README, package-level manual page, manual page of the functions that use the dependency). Example.
- Within the code, for instance:
if (!(require("targets")) {
stop("You can install targets with install.packages('targets', repos = c('https://ropensci.r-universe.dev', 'https://cloud.r-project.org'))")
}
or a solution that will automatically prompt the user to install the missing package:
::check_installed("targets", action = function(...) install.packages('targets', repos = c('https://ropensci.r-universe.dev', 'https://cloud.r-project.org'))) rlang
9.2 How to use a universe on regular continous integration?
If you want to test a package against versions of other packages that are in a universe, on GitHub Actions you can use the extra-repositories
field of the r-lib/actions
setup-r action.