knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

pkg.deps

R build status

R packages depend on other R packages. On Linux, R packages can also depend on system requirements. As an example, the {curl} package has this field in its DESCRIPTION file and on its CRAN page:

SystemRequirements: libcurl: libcurl-devel (rpm) or libcurl4-openssl-dev (deb).

When installing a lot of packages (or packages with lots of dependencies) it can be time consuming to check these requirements manually. Running install.packages, note which packages fail and look up their dependencies can be very time consuming -- in particular when making Docker images.

The goal of {pkg.deps} is to help find system requirements for packages and their dependencies. I consider two scenarios:

The second scenario is relevant because some packages use generic descriptions of their requirements. As an example, the {data.table} package notes the system requirement zlib which on Ubuntu is zlib1g-dev and on Red Hat is zlib-devel. To alleviate this RStudio has a repo with System Requirements for R Packages. I utilize this in a low-tech manner where {pkg.deps} consult the rules in local clone.

Installation

The package is only available on GitHub and can be installed with the remotes package using this command:

remotes::install_github("robertdj/pkg.deps")

Example 1

There are three functions in {pkg.deps}. The first function simply returns all non-base dependencies:

pkg.deps::get_package_deps("httr")

The second returns all dependencies with system requirements in free-form, that is, as they appear in their DESCRIPTION files:

pkg.deps::get_package_reqs("httr")

The output is a subset of a dataframe, so it also includes row numbers. The final function converts the output from get_package_reqs to distribution specific libraries. It needs the path to a local copy/clone of System Requirements for R Packages, which in this example is ../r-system-requirements.

For Ubuntu we get this output:

reqs <- pkg.deps::get_package_reqs("httr")
pkg.deps::distro_req(reqs, "ubuntu", "../r-system-requirements")

Compare this with the output for Redhat:

pkg.deps::distro_req(reqs, "redhat", "../r-system-requirements")

I am not trying anything fancy to help with r-system-requirements -- distro_req simply fails if the JSON files with rules are not in the expected location.

Example 2

In an R(Studio) project that is not a package there is no base R way of keeping track of dependencies. The {renv} package can help out with a formal tracking and it has a function for discovering dependencies:

deps <- renv::dependencies()

Here I am running it in the {pkg.deps} package project itself and the dependencies are

unique(deps$Package)

This vector can be used in get_package_deps as in the example above. A final function from {pkg.deps} offers to remove the base R packages so that the result is ready for install.packages:

pkg.deps::remove_base_packages(deps$Package)


robertdj/pkg.deps documentation built on June 25, 2021, 9:51 p.m.