Look up dependencies of R packages from various sources.
Arguments
- refs
Package names or references. See 'Package references' for the syntax.
- ...
Additional arguments, passed to
pkg_deps$new()
.
Details
new_pkg_deps()
creates a new object from the pkg_deps
class.
The advantage of new_pkg_deps()
compared to using the pkg_deps
constructor directly is that it avoids making pkgdepends a build time
dependency.
The usual steps to query package dependencies are:
Create a
pkg_deps
object withnew_pkg_deps()
.Resolve all possible dependencies with
pkg_deps$resolve()
.Solve the dependencies, to obtain a subset of all possible dependencies that can be installed together, with
pkg_deps$solve()
.Call
pkg_deps$get_solution()
to list the result of the dependency solver.
Methods
Method new()
Create a new pkg_deps
object. Consider using new_pkg_deps()
instead of calling the constructor directly.
The returned object can be used to look up (recursive) dependencies
of R packages from various sources. To perform the actual lookup,
you'll need to call the resolve()
method.
Arguments
refs
Package names or references. See 'Package references' for the syntax.
config
Configuration options, a named list. See 'Configuration'.
policy
Solution policy. See 'The dependency solver'.
remote_types
Custom remote ref types, this is for advanced use, and experimental currently.
Method get_config()
Configuration options for the pkg_deps
object. See
'Configuration' for details.
Returns
See 'Configuration' for the configuration entries.
Method resolve()
Resolve the dependencies of the specified package references. This usually means downloading metadata from CRAN and Bioconductor, unless already cached, and also from GitHub if GitHub refs were included, either directly or indirectly. See 'Dependency resolution' for details.
Method async_resolve()
The same as resolve()
, but asynchronous.
This method is for advanced use.
Method get_resolution()
Query the result of the dependency resolution. This method can be
called after resolve()
has completed.
Returns
A pkg_resolution_result object, which is also a data frame. See 'Dependency resolution' for its columns.
Method get_solve_policy()
Returns the current policy of the dependency solver. See 'The dependency solver' for details.
Method set_solve_policy()
Set the current policy of the dependency solver. If the object already contains a solution and the new policy is different than the old policy, then the solution is deleted. See 'The dependency solver' for details.
Usage
pkg_deps$set_solve_policy(policy = c("lazy", "upgrade"))
Method solve()
Solve the package dependencies. Out of the resolved dependencies, it works out a set of packages, that can be installed together to create a functional installation. The set includes all directly specified packages, and all required (or suggested, depending on the configuration) packages as well. It includes every package at most once. See 'The dependency solver' for details.
solve()
calls resolve()
automatically, if it
hasn't been called yet.
Method get_solution()
Returns the solution of the package dependencies.
Returns
A pkg_solution_result object, which is a list. See pkg_solution_result for details.
Method stop_for_solution_error()
Error if the dependency solver failed to find a consistent set of packages that can be installed together.
Method draw()
Draw a tree of package dependencies. It returns a tree
object, see
cli::tree()
. Printing this object prints the dependency tree to the
screen.
Returns
A tree
object from the cli package, see cli::tree()
.
Method format()
Format a pkg_deps
object, typically for printing.
Method print()
Prints a pkg_deps
object to the screen. The printout includes:
The package refs.
Whether the object has the resolved dependencies.
Whether the resolution had errors.
Whether the object has the solved dependencies.
Whether the solution had errors.
Advice on which methods to call next.
See the example below.
Examples
# Method initialize()
pd <- pkg_deps$new("r-lib/pkgdepends")
pd
#> <pkg_dependencies>
#> + refs:
#> - r-lib/pkgdepends
#> (use `$resolve()` to resolve dependencies)
#> (use `$solve()` to solve dependencies)
# Method get_refs()
pd <- new_pkg_deps(c("pak", "jsonlite"))
pd$get_refs()
#> [1] "pak" "jsonlite"
# Method get_config()
pd <- new_pkg_deps("pak")
pd$get_config()
#> # pkg config
#> ## build_vignettes
#> <default>
#> [1] FALSE
#>
#> ## sysreqs_verbose
#> <default>
#> [1] TRUE
#>
#> ## sysreqs_db_update
#> <default>
#> [1] TRUE
#>
#> ## metadata_cache_dir
#> <default>
#> [1] "/tmp/RtmpQJsVyT/file190e539de326"
#>
#> ## platforms
#> <default>
#> [1] "x86_64-pc-linux-gnu-ubuntu-22.04" "source"
#>
#> ## goal
#> <default>
#> [1] "unknown"
#>
#> ## r_versions
#> <default>
#> [1] "4.4.1"
#>
#> ## cache_dir
#> <default>
#> [1] "/tmp/RtmpQJsVyT/file190e7032c895"
#>
#> ## library
#> <set>
#> [1] "/tmp/RtmpQJsVyT/file190e21560c80"
#>
#> ## metadata_update_after
#> <default>
#> Time difference of 24 hours
#>
#> ## include_linkingto
#> <default>
#> [1] FALSE
#>
#> ## sysreqs_rspm_repo_id
#> <default>
#> [1] "1"
#>
#> ## sysreqs_update
#> <default>
#> [1] TRUE
#>
#> ## package_cache_dir
#> <default>
#> NULL
#>
#> ## sysreqs_rspm_url
#> <default>
#> [1] "https://packagemanager.posit.co"
#>
#> ## sysreqs_sudo
#> <default>
#> [1] TRUE
#>
#> ## sysreqs_db_update_timeout
#> <default>
#> Time difference of 5 secs
#>
#> ## sysreqs_lookup_system
#> <set>
#> [1] FALSE
#>
#> ## git_submodules
#> <default>
#> [1] FALSE
#>
#> ## sysreqs_platform
#> <default>
#> [1] "x86_64-pc-linux-gnu-ubuntu-22.04"
#>
#> ## dependencies
#> <default>
#> [1] "Depends" "Imports" "LinkingTo"
#>
#> ## sysreqs
#> <default>
#> [1] TRUE
#>
#> ## sysreqs_dry_run
#> <default>
#> [1] FALSE
#>
#> ## windows_archs
#> <default>
#> [1] "prefer-x64"
#>
#> ## use_bioconductor
#> <default>
#> [1] TRUE
#>
#> ## cran_mirror
#> <default>
#> CRAN
#> "https://cran.rstudio.com"
#>
# Method resolve()
pd <- new_pkg_deps("pak")
pd$resolve()
#>
#> ✔ Updated metadata database: 3.50 MB in 3 files.
#>
#> ℹ Updating metadata database
#> ✔ Updating metadata database ... done
#>
pd$get_resolution()
#> # A data frame: 2 × 35
#> ref type direct directpkg status package version license
#> <chr> <chr> <lgl> <lgl> <chr> <chr> <chr> <chr>
#> 1 pak standard TRUE TRUE OK pak 0.8.0 GPL-3
#> 2 pak standard TRUE TRUE OK pak 0.8.0 GPL-3
#> # ℹ 27 more variables: needscompilation <lgl>, priority <chr>,
#> # md5sum <chr>, sha256 <chr>, filesize <int>, built <chr>,
#> # platform <chr>, rversion <chr>, repotype <chr>, repodir <chr>,
#> # target <chr>, deps <list>, mirror <chr>, sources <list>,
#> # remote <list>, error <list>, metadata <list>, extra <list>,
#> # dep_types <list>, params <list>, sysreqs <chr>, os_type <chr>,
#> # cache_status <chr>, sysreqs_packages <list>, …
# Method get_resolution()
pd <- new_pkg_deps("r-lib/pkgdepends")
pd$resolve()
pd$get_resolution()
#> # A data frame: 27 × 35
#> ref type direct directpkg status package version license
#> <chr> <chr> <lgl> <lgl> <chr> <chr> <chr> <chr>
#> 1 r-lib/pkgdepends github TRUE TRUE OK pkgdep… 0.8.0.… MIT + …
#> 2 callr stand… FALSE FALSE OK callr 3.7.6 MIT + …
#> 3 cli stand… FALSE FALSE OK cli 3.6.3 MIT + …
#> 4 curl stand… FALSE FALSE OK curl 5.2.2 MIT + …
#> 5 desc stand… FALSE FALSE OK desc 1.4.3 MIT + …
#> 6 filelock stand… FALSE FALSE OK filelo… 1.0.3 MIT + …
#> 7 jsonlite stand… FALSE FALSE OK jsonli… 1.8.8 MIT + …
#> 8 lpSolve stand… FALSE FALSE OK lpSolve 5.6.20 LGPL-2
#> 9 pkgbuild stand… FALSE FALSE OK pkgbui… 1.4.4 MIT + …
#> 10 pkgcache stand… FALSE FALSE OK pkgcac… 2.2.2 MIT + …
#> # ℹ 17 more rows
#> # ℹ 27 more variables: needscompilation <lgl>, priority <chr>,
#> # md5sum <chr>, sha256 <chr>, filesize <int>, built <chr>,
#> # platform <chr>, rversion <chr>, repotype <chr>, repodir <chr>,
#> # target <chr>, deps <list>, mirror <chr>, sources <list>,
#> # remote <list>, error <list>, metadata <list>, extra <list>,
#> # dep_types <list>, params <list>, sysreqs <chr>, os_type <chr>, …
# Method get_solve_policy()
pdi <- new_pkg_deps("r-lib/pkgdepends")
pdi$get_solve_policy()
#> [1] "lazy"
pdi$set_solve_policy("upgrade")
pdi$get_solve_policy()
#> [1] "upgrade"
# Method set_solve_policy()
pdi <- new_pkg_deps("r-lib/pkgdepends")
pdi$get_solve_policy()
#> [1] "lazy"
pdi$set_solve_policy("upgrade")
pdi$get_solve_policy()
#> [1] "upgrade"
# Method solve()
pd <- new_pkg_deps("r-lib/pkgdepends")
pd$resolve()
pd$solve()
pd$get_solution()
#> <pkg_solution>
#> + result: OK
#> + refs:
#> - r-lib/pkgdepends
#> + constraints (62):
#> - select pkgdepends exactly once
#> - select callr at most once
#> - select cli at most once
#> - select curl at most once
#> - select desc at most once
#> - select filelock at most once
#> - select jsonlite at most once
#> - select lpSolve at most once
#> - select pkgbuild at most once
#> - select pkgcache at most once
#> ...
#> + solution:
#> - R6
#> - callr
#> - cli
#> - curl
#> - desc
#> - filelock
#> - jsonlite
#> - lpSolve
#> - pkgbuild
#> - pkgcache
#> - processx
#> - ps
#> - r-lib/pkgdepends
#> - zip
# Method get_solution()
pd <- new_pkg_deps("pkgload")
pd$resolve()
pd$solve()
pd$get_solution()
#> <pkg_solution>
#> + result: OK
#> + refs:
#> - pkgload
#> + constraints (51):
#> - select pkgload exactly once
#> - select callr at most once
#> - select cli at most once
#> - select desc at most once
#> - select fs at most once
#> - select glue at most once
#> - select lifecycle at most once
#> - select pkgbuild at most once
#> - select processx at most once
#> - select ps at most once
#> ...
#> + solution:
#> - R6
#> - callr
#> - cli
#> - desc
#> - fs
#> - glue
#> - lifecycle
#> - pkgbuild
#> - pkgload
#> - processx
#> - ps
#> - rlang
#> - rprojroot
#> - withr
# Method stop_for_solution_error()
# This is an error, because the packages conflict:
pd <- new_pkg_deps(
c("r-lib/pak", "cran::pak"),
config = list(library = tempfile())
)
pd$resolve()
pd$solve()
pd
#> <pkg_dependencies>
#> + refs:
#> - r-lib/pak
#> - cran::pak
#> + has resolution (+0 dependencies)
#> + has solution
#> x has solution errors
#> (use `$get_resolution()` to see resolution results)
#> (use `$show_solution()` to see the dependencies
#> (use `$get_solution()` to see the full solution results)
# This fails:
# pd$stop_for_solution_error()
# Method draw()
pd <- new_pkg_deps("pkgload")
pd$solve()
pd$draw()
#> pkgload 1.4.0 [new][dl] (unknown size)
#> ├─cli 3.6.3 [new][dl] (unknown size)
#> ├─desc 1.4.3 [new][dl] (unknown size)
#> │ ├─cli
#> │ └─R6 2.5.1 [new][dl] (unknown size)
#> ├─fs 1.6.4 [new][dl] (unknown size)
#> ├─glue 1.7.0 [new][dl] (unknown size)
#> ├─lifecycle 1.0.4 [new][dl] (unknown size)
#> │ ├─cli
#> │ ├─glue
#> │ └─rlang 1.1.4 [new][dl] (unknown size)
#> ├─pkgbuild 1.4.4 [new][dl] (unknown size)
#> │ ├─callr 3.7.6 [new][dl] (unknown size)
#> │ │ ├─processx 3.8.4 [new][dl] (unknown size)
#> │ │ │ ├─ps 1.7.7 [new][dl] (unknown size)
#> │ │ │ └─R6
#> │ │ └─R6
#> │ ├─cli
#> │ ├─desc
#> │ ├─processx
#> │ └─R6
#> ├─processx
#> ├─rlang
#> ├─rprojroot 2.0.4 [new][dl] (unknown size)
#> └─withr 3.0.1 [new][dl] (unknown size)
#>
#> Key: [new] new | [dl] download
# Method print()
pd <- new_pkg_deps("r-lib/pkgdepends")
pd
#> <pkg_dependencies>
#> + refs:
#> - r-lib/pkgdepends
#> (use `$resolve()` to resolve dependencies)
#> (use `$solve()` to solve dependencies)
pd$resolve()
pd
#> <pkg_dependencies>
#> + refs:
#> - r-lib/pkgdepends
#> + has resolution (+13 dependencies)
#> (use `$get_resolution()` to see resolution results)
#> (use `$solve()` to solve dependencies)
pd$solve()
pd
#> <pkg_dependencies>
#> + refs:
#> - r-lib/pkgdepends
#> + has resolution (+13 dependencies)
#> + has solution
#> (use `$get_resolution()` to see resolution results)
#> (use `$show_solution()` to see the dependencies
#> (use `$get_solution()` to see the full solution results)
#> (use `$draw()` to draw the dependency tree)