This will first look in local filesystem (in .libPaths()) and will use a local package to find its dependencies. If the package doesn't exist locally, including whether it is the correct version, then it will look in (currently) CRAN and its archives (if the current CRAN version is not the desired version to check). It will also look on GitHub if the package description is of the form of a GitHub package with format account/repo@branch or account/repo@commit. For this, it will attempt to get package dependencies from the GitHub DESCRIPTION file. This is intended to replace tools::package_dependencies or pkgDep in the miniCRAN package, but with modifications to allow multiple sources to be searched in the same function call.

pkgDep2 is a convenience wrapper of pkgDep that "goes one level in", i.e., the first order dependencies, and runs the pkgDep on those.

This is a wrapper around tools::dependsOnPkgs, but with the added option of sorted, which will sort them such that the packages at the top will have the least number of dependencies that are in pkgs. This is essentially a topological sort, but it is done heuristically. This can be used to e.g., detach or unloadNamespace packages in order so that they each of their dependencies are detached or unloaded first.

pkgDepAlt is a newer, still experimental approach to pkgDep, which has different internal algorithms. With current testing, it appears to be slightly more accurate for (some unknown, as of yet) edge cases. One known case is when the a package is installed locally package, but is not the version that is requested with pkgDep, the function will default to the local, installed, and incorrect package dependencies. pkgDepAlt gets this case correct. This function may eventually replace pkgDep.

pkgDep(
  packages,
  libPath = .libPaths(),
  which = c("Depends", "Imports", "LinkingTo"),
  recursive = FALSE,
  depends,
  imports,
  suggests,
  linkingTo,
  repos = getOption("repos"),
  keepVersionNumber = TRUE,
  includeBase = FALSE,
  sort = TRUE,
  purge = getOption("Require.purge", FALSE)
)

pkgDep2(
  packages,
  recursive = TRUE,
  which = c("Depends", "Imports", "LinkingTo"),
  depends,
  imports,
  suggests,
  linkingTo,
  repos = getOption("repos"),
  sorted = TRUE,
  purge = getOption("Require.purge", FALSE)
)

pkgDepTopoSort(
  pkgs,
  deps,
  reverse = FALSE,
  topoSort = TRUE,
  useAllInSearch = FALSE,
  returnFull = TRUE,
  recursive = TRUE,
  purge = getOption("Require.purge", FALSE)
)

pkgDepAlt(
  packages,
  libPath = .libPaths(),
  which = c("Depends", "Imports", "LinkingTo", "Remotes"),
  recursive = FALSE,
  depends,
  imports,
  suggests,
  linkingTo,
  enhances,
  remotes,
  repos = getOption("repos"),
  keepVersionNumber = TRUE,
  includeBase = FALSE,
  sort = TRUE,
  purge = getOption("Require.purge", FALSE)
)

Arguments

packages

Character vector of packages to install via install.packages, then load (i.e., with library). If it is one package, it can be unquoted (as in require). In the case of a GitHub package, it will be assumed that the name of the repository is the name of the package. If this is not the case, then pass a named character vector here, where the names are the package names that could be different than the GitHub repository name.

libPath

A path to search for installed packages. Defaults to .libPaths()

which

a character vector listing the types of dependencies, a subset of c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances"). Character string "all" is shorthand for that vector, character string "most" for the same vector without "Enhances".

recursive

Logical. Should dependencies of dependencies be searched, recursively. NOTE: Dependencies of suggests will not be recursive. Default TRUE.

depends

Logical. Include packages listed in "Depends". Default TRUE.

imports

Logical. Include packages listed in "Imports". Default TRUE.

suggests

Logical. Include packages listed in "Suggests". Default FALSE.

linkingTo

Logical. Include packages listed in "LinkingTo". Default TRUE.

repos

The remote repository (e.g., a CRAN mirror), passed to either install.packages, install_github or installVersions.

keepVersionNumber

Logical. If TRUE, then the package dependencies returned will include version number. Default is FALSE

includeBase

Logical. Should R base packages be included, specifically, those in tail(.libPath(), 1)

sort

Logical. If TRUE, the default, then the packages will be sorted alphabetically. If FALSE, the packages will not have a discernible order as they will be a concatenation of the possibly recursive package dependencies.

purge

Logical. Should all caches be purged Default is getOption("Require.purge", FALSE). There is a lot of internal caching of results throughout the Require package. These help with speed and reduce calls to internet sources. However, sometimes these caches must be purged. The cached values are renewed when found to be too old, with the age limit. This maximum age can be set in seconds with the environment variable R_AVAILABLE_PACKAGES_CACHE_CONTROL_MAX_AGE, or if unset, defaults to 3600 (one hour -- see available.packages).

Internally, there are calls to available.packages

sorted

Logical. If TRUE, the default, the packages will be sorted in the returned list from most number of dependencies to least.

pkgs

A vector of package names to evaluate their reverse depends (i.e., the packages that use each of these packages)

deps

An optional named list of (reverse) dependencies. If not supplied, then tools::dependsOnPkgs(..., recursive = TRUE) will be used

reverse

Logical. If TRUE, then this will use tools::pkgDependsOn to determine which packages depend on the pkgs

topoSort

Logical. If TRUE, the default, then the returned list of packages will be in order with the least number of dependencies listed in pkgs at the top of the list.

useAllInSearch

Logical. If TRUE, then all non-core R packages in search() will be appended to pkgs to allow those to also be identified

returnFull

Logical. Primarily useful when reverse = TRUE. If TRUE, then then all installed packages will be searched. If FALSE, the default, only packages that are currently in the search() path and passed in pkgs will be included in the possible reverse dependencies.

enhances

Logical. Include packages listed in "Enhances". Default FALSE.

remotes

Logical. Include packages listed in "Remotes". This is only relevant for GitHub packages. Default TRUE.

Value

A possibly ordered, named (with packages as names) list where list elements are either full reverse depends.

Note

tools::package_dependencies and pkgDep will differ under the following circumstances:

  1. GitHub packages are not detected using tools::package_dependencies;

  2. tools::package_dependencies does not detect the dependencies of base packages among themselves, e.g., methods depends on stats and graphics.

Examples

if (FALSE) { pkgDep("Require") pkgDep("Require", keepVersionNumber = FALSE) # just names pkgDep("PredictiveEcology/reproducible") # GitHub pkgDep("PredictiveEcology/reproducible", recursive = TRUE) # GitHub pkgDep(c("PredictiveEcology/reproducible", "Require")) # GitHub package and local packages pkgDep(c("PredictiveEcology/reproducible", "Require", "plyr")) # GitHub, local, and CRAN packages } if (FALSE) { pkgDep2("Require") # much bigger one pkgDep2("reproducible") } if (FALSE) { pkgDepTopoSort(c("Require", "data.table"), reverse = TRUE) }