9 Using dependencies from R-universe
9.1 CRAN-like repository URLs
R-universe provides CRAN-like repository URLs for each universe. For example, the following functions work:
# All the packages in the tidyverse universe
available.packages(repos = "https://tidyverse.r-universe.dev")
# Installs dplyr and its dependencies from the tidyverse universe,
# and dependencies that do not exist in the tidyverse universe are installed from CRAN
install.packages("dplyr", repos = c("https://tidyverse.r-universe.dev", "https://cloud.r-project.org"))If you want to install only specific packages from the universe, and install the other packages from CRAN, you can specify the repository for only the package you want to install from the universe as follows:
# Package specific repository for dplyr
available.packages(repos = "https://tidyverse.r-universe.dev/dplyr")
# Installs dplyr from the tidyverse universe,
# and its dependencies are installed from CRAN
install.packages("dplyr", repos = c("https://tidyverse.r-universe.dev/dplyr", "https://cloud.r-project.org"))To install binary versions, append bin/linux/... to the URL. See Linux binaries for details. Combine with Posit Package Manager repositories for binaries for CRAN versions.
# All tidyverse binaries on Ubuntu Noble for ARM for R 4.5:
install.packages("dplyr", repos = "https://tidyverse.r-universe.dev/bin/linux/noble-arm64/4.5")
# Only dplyr on Ubuntu Noble for ARM for R 4.5:
install.packages("dplyr", repos = "https://tidyverse.r-universe.dev/dplyr/bin/linux/noble-arm64/4.5")9.2 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_repositoriesfield 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:
rlang::check_installed("targets", action = function(...) install.packages('targets', repos = c('https://ropensci.r-universe.dev', 'https://cloud.r-project.org')))9.3 How to use a universe on regular continuous 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.