This is a wrapper around tools::dependsOnPkgs,
but with the added option of topoSort, which
will sort them such that the packages at the top will have
the least number of dependencies that are in packages.
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.
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 will first look in local filesystem (in .libPaths()) and will use a
local package to find its dependencies. If the package does not 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.
pkgDepTopoSort(
packages,
deps,
reverse = FALSE,
topoSort = TRUE,
libPaths,
useAllInSearch = FALSE,
returnFull = TRUE,
recursive = TRUE,
purge = getOption("Require.purge", FALSE),
which = c("Depends", "Imports", "LinkingTo"),
type = getOption("pkgType"),
verbose = getOption("Require.verbose"),
...
)pkgDep2(...)
pkgDep(
packages,
libPaths,
which = c("Depends", "Imports", "LinkingTo"),
recursive = TRUE,
depends,
imports,
suggests,
linkingTo,
repos = getOption("repos"),
keepVersionNumber = TRUE,
includeBase = FALSE,
includeSelf = TRUE,
sort = TRUE,
simplify = TRUE,
purge = getOption("Require.purge", FALSE),
verbose = getOption("Require.verbose"),
type = getOption("pkgType"),
Additional_repositories = FALSE,
...
)
A possibly ordered, named (with packages as names) list where list elements are either full reverse depends.
Either a character vector of packages to install via
install.packages, then load (i.e., with library), or, for convenience,
a vector or list (using c or list) of unquoted package names to install
and/or load (as in require, but vectorized). Passing vectors of names may
not work in all cases, so user should confirm before relying on this behaviour
in operational code.
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.
As a convenience for copy-pasting long lists, any character element that
contains newlines is split into one package per line, with whitespace
trimmed and blank or #-prefixed lines dropped. For example,
Require("\n dplyr\n # ggplot2\n PredictiveEcology/LandR@development\n")
is equivalent to
Require(c("dplyr", "PredictiveEcology/LandR@development")).
Alternatively, an unquoted {...} block is accepted, with each line
treated as one package spec, e.g.
Require({ dplyr; lme4; PredictiveEcology/LandR@development }).
Note that R's parser strips comments inside {...} before this function
runs, so to omit a package delete the line (or comment it out -- both
have the same effect). Version constraints such as pkg (>= 1.0) do
not parse inside {...} and must use the quoted string form.
An optional named list of (reverse) dependencies.
If not supplied, then tools::dependsOnPkgs(..., recursive = TRUE)
will be used
Logical. If TRUE, then this will use tools::pkgDependsOn
to determine which packages depend on the packages
Logical. If TRUE, the default, then
the returned list of packages will be in order with the
least number of dependencies listed in packages at
the top of the list.
A path to search for installed packages. Defaults to
.libPaths()
Logical. If TRUE, then all non-core
R packages in search() will be appended to packages
to allow those to also be identified
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 packages will be included
in the possible reverse dependencies.
Logical. Should dependencies of dependencies be searched,
recursively. NOTE: Dependencies of suggests will not be recursive. Default
TRUE.
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 utils::available.packages).
Internally, there are calls to available.packages.
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".
Numeric or logical indicating how verbose should the function
be. If -1 or -2, then as little verbosity as possible. If 0 or FALSE,
then minimal outputs; if 1 or TRUE, more outputs; 2 even more. NOTE: in
Require function, when verbose >= 2, also returns details as if
returnDetails = TRUE (for backwards compatibility).
Currently only dependencies as an alternative to which. If specified,
then which will be ignored.
Logical. Include packages listed in "Depends". Default TRUE.
Logical. Include packages listed in "Imports". Default TRUE.
Logical. Include packages listed in "Suggests". Default
FALSE.
Logical. Include packages listed in "LinkingTo". Default
TRUE.
The remote repository (e.g., a CRAN mirror), passed to either
install.packages, install_github or installVersions.
When options(Require.usePak = TRUE): repos is added to pak's repository
list via options(repos). However, pak always includes CRAN and Bioconductor as
built-in defaults regardless of this setting -- repos can only add sources,
it cannot prevent pak from also searching CRAN. This differs from the default
(usePak = FALSE) behaviour where repos strictly controls which repositories
are used. Use pak::cache_clean() to clear pak's download cache if needed.
Logical. If TRUE, then the package dependencies
returned will include version number. Default is FALSE
Logical. Should R base packages be included, specifically,
those in tail(.libPaths(), 1)
Logical. If TRUE, the default, then the dependencies
will include the package itself in the returned list elements, otherwise,
only the "dependencies"
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.
Logical or numeric. If TRUE (or > 0), the default,
the return object is "just" a character vector of package names
(with version requirements). If FALSE (or 0),
then a data.table will be returned with 4 columns,
Package, packageFullName, parentPackage (the package name for which the
given line entry is a dependency; will be "user" if it was user supplied)
and deps, which is a list of data.tables
of all dependencies. If a negative number, then it will return a similar data.table
as with FALSE, however, duplications in the recursive package dependencies
are left intact.
Logical. If TRUE, then pkgDep will return
a list of data.table objects (instead of character vectors)
with a column packageFullName and possibly a second column Additional_repositories,
which may have been specified in a DESCRIPTION file. NOTE: THIS ALTERS
THE OUTPUT CLASS
# \donttest{
if (Require:::.runLongExamples()) {
opts <- Require:::.setupExample()
pkgDepTopoSort(c("Require", "data.table"), reverse = TRUE)
Require:::.cleanup(opts)
}
# }
# \donttest{
if (Require:::.runLongExamples()) {
opts <- Require:::.setupExample()
pkgDep2("reproducible")
# much bigger one
pkgDep2("tidyverse")
Require:::.cleanup(opts)
}
# }
# \donttest{
if (Require:::.runLongExamples()) {
opts <- Require:::.setupExample()
pkgDep("tidyverse", recursive = TRUE)
# GitHub, local, and CRAN packages
pkgDep(c("PredictiveEcology/reproducible", "Require", "plyr"))
Require:::.cleanup(opts)
}
# }
Run the code above in your browser using DataLab