Look up dependencies of R packages from various sources.

new_pkg_deps(refs, ...)

Arguments

refs

Package names or references. See 'Package references' for the syntax.

...

Additional arguments, passed to pkg_deps$new().

Value

new_pkg_deps() returns a new pkg_deps object.

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:

  1. Create a pkg_deps object with new_pkg_deps().

  2. Resolve all possible dependencies with pkg_deps$resolve().

  3. Solve the dependencies, to obtain a subset of all possible dependencies that can be installed together, with pkg_deps$solve().

  4. Call pkg_deps$get_solution() to list the result of the dependency solver.

Methods

Public 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.

Usage

pkg_deps$new(
  refs,
  config = list(),
  policy = c("lazy", "upgrade"),
  remote_types = NULL
)

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.

Returns

A new pkg_deps object.


Method get_refs()

The package refs that were used to create the pkg_deps object.

Usage

pkg_deps$get_refs()

Returns

A character vector of package refs that were used to create the pkg_deps object.


Method get_config()

Configuration options for the pkg_deps object. See 'Configuration' for details.

Usage

pkg_deps$get_config()

Returns

Named list. See 'Configuration' for the configuration options.


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.

Usage

pkg_deps$resolve()

Returns

The pkg_deps object itself, invisibly.


Method async_resolve()

The same as resolve(), but asynchronous. This method is for advanced use.

Usage

pkg_deps$async_resolve()

Returns

A deferred value.


Method get_resolution()

Query the result of the dependency resolution. This method can be called after resolve() has completed.

Usage

pkg_deps$get_resolution()

Returns

A pkg_resolution_result object, which is also a tibble. See 'Dependency resolution' for its columns.


Method get_solve_policy()

Returns the current policy of the dependency solver. See 'The dependency solver' for details.

Usage

pkg_deps$get_solve_policy()

Returns

A character vector of length one.


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"))

Arguments

policy

Policy to set.


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.

Usage

pkg_deps$solve()

Returns

The pkg_deps object itself, invisibly.


Method get_solution()

Returns the solution of the package dependencies.

Usage

pkg_deps$get_solution()

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.

Usage

pkg_deps$stop_for_solution_error()


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.

Usage

pkg_deps$draw()

Returns

A tree object from the cli package, see cli::tree().


Method format()

Format a pkg_deps object, typically for printing.

Usage

pkg_deps$format(...)

Arguments

...

Not used currently.

Returns

A character vector, each element should be a line in the printout.


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.

Usage

pkg_deps$print(...)

Arguments

...

not used currently.

Returns

The pkg_deps object itself, invisibly.


Method clone()

The objects of this class are cloneable with this method.

Usage

pkg_deps$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

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()
#> + config: #> - library: /tmp/RtmpReCZ7Q/file2d4a5b16cc6e #> - cache_dir: /tmp/RtmpReCZ7Q/file2d4a40b8867b #> - package_cache_dir: <default> #> - metadata_cache_dir: /tmp/RtmpReCZ7Q/file2d4a28573343 #> - platforms: source #> - cran-mirror: https://cloud.r-project.org #> - dependencies: direct: Depends, Imports, LinkingTo, indirect: Depends, Imports, LinkingTo #> - r-versions: 4.1.0 #> - build-vignettes: FALSE #> - metadata-update-after: 24 hours
# Method resolve() pd <- new_pkg_deps("pak") pd$resolve()
#>
#> Updated metadata database: 3.07 MB in 7 files.
#>
#> Updating metadata database
#> Updating metadata database ... done
#>
pd$get_resolution()
#> # A tibble: 84 x 29 #> ref type direct directpkg status package version license needscompilation #> <chr> <chr> <lgl> <lgl> <chr> <chr> <chr> <chr> <lgl> #> 1 R6 stan… FALSE FALSE OK R6 2.5.0 MIT + … FALSE #> 2 asser… stan… FALSE FALSE OK assert… 0.2.1 GPL-3 FALSE #> 3 base6… stan… FALSE FALSE OK base64… 0.1-3 GPL-2 … TRUE #> 4 callr stan… FALSE FALSE OK callr 3.7.0 MIT + … FALSE #> 5 cli stan… FALSE FALSE OK cli 2.5.0 MIT + … FALSE #> 6 cliapp stan… FALSE FALSE OK cliapp 0.1.1 MIT + … FALSE #> 7 crayon stan… FALSE FALSE OK crayon 1.4.1 MIT + … FALSE #> 8 curl stan… FALSE FALSE OK curl 4.3.2 MIT + … TRUE #> 9 desc stan… FALSE FALSE OK desc 1.3.0 MIT + … FALSE #> 10 digest stan… FALSE FALSE OK digest 0.6.27 GPL (>… TRUE #> # … with 74 more rows, and 20 more variables: 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>, cache_status <chr>
# Method get_resolution() pd <- new_pkg_deps("r-lib/pkgdepends") pd$resolve() pd$get_resolution()
#> # A tibble: 67 x 29 #> ref type direct directpkg status package version license needscompilation #> <chr> <chr> <lgl> <lgl> <chr> <chr> <chr> <chr> <lgl> #> 1 r-lib… gith… TRUE TRUE OK pkgdep… 0.1.2.… MIT + … TRUE #> 2 R6 stan… FALSE FALSE OK R6 2.5.0 MIT + … FALSE #> 3 asser… stan… FALSE FALSE OK assert… 0.2.1 GPL-3 FALSE #> 4 callr stan… FALSE FALSE OK callr 3.7.0 MIT + … FALSE #> 5 cli stan… FALSE FALSE OK cli 2.5.0 MIT + … FALSE #> 6 crayon stan… FALSE FALSE OK crayon 1.4.1 MIT + … FALSE #> 7 curl stan… FALSE FALSE OK curl 4.3.2 MIT + … TRUE #> 8 desc stan… FALSE FALSE OK desc 1.3.0 MIT + … FALSE #> 9 digest stan… FALSE FALSE OK digest 0.6.27 GPL (>… TRUE #> 10 ellip… stan… FALSE FALSE OK ellips… 0.3.2 MIT + … TRUE #> # … with 57 more rows, and 20 more variables: priority <chr>, md5sum <chr>, #> # sha256 <chr>, filesize <int>, built <chr>, platform <chr>, rversion <chr>, #> # repotype <chr>, repodir <chr>, target <glue>, deps <list>, mirror <chr>, #> # sources <list>, remote <list>, error <list>, metadata <list>, extra <list>, #> # dep_types <list>, params <list>, cache_status <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 (141): #> - select pkgdepends exactly once #> - select R6 at most once #> - select assertthat at most once #> - select callr at most once #> - select cli at most once #> - select crayon at most once #> - select curl at most once #> - select desc at most once #> - select digest at most once #> - select ellipsis at most once #> ... #> + solution: #> - assertthat #> - callr #> - cli #> - crayon #> - curl #> - desc #> - digest #> - ellipsis #> - fansi #> - filelock #> - glue #> - jsonlite #> - lifecycle #> - lpSolve #> - magrittr #> - pillar #> - pkgbuild #> - pkgcache #> - pkgconfig #> - prettyunits #> - processx #> - ps #> - r-lib/pkgdepends #> - R6 #> - rappdirs #> - rematch2 #> - rlang #> - rprojroot #> - tibble #> - utf8 #> - uuid #> - vctrs #> - withr #> - zip
# Method get_solution() pd <- new_pkg_deps("pkgload") pd$resolve() pd$solve() pd$get_solution()
#> <pkg_solution> #> + result: OK #> + refs: #> - pkgload #> + constraints (31): #> - select pkgload exactly once #> - select R6 at most once #> - select cli at most once #> - select crayon at most once #> - select desc at most once #> - select glue at most once #> - select rlang at most once #> - select rprojroot at most once #> - select rstudioapi at most once #> - select withr at most once #> ... #> + solution: #> - cli #> - crayon #> - desc #> - glue #> - pkgload #> - R6 #> - rlang #> - rprojroot #> - rstudioapi #> - 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 (+41 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.2.1 [new][bld][cmp][dl] (unknown size) #> ├─cli 2.5.0 [new][bld][dl] (unknown size) #> │ └─glue 1.4.2 [new][bld][cmp][dl] (unknown size) #> ├─crayon 1.4.1 [new][bld][dl] (unknown size) #> ├─desc 1.3.0 [new][bld][dl] (unknown size) #> │ ├─R6 2.5.0 [new][bld][dl] (unknown size) #> │ ├─crayon #> │ └─rprojroot 2.0.2 [new][bld][dl] (unknown size) #> ├─rlang 0.4.11 [new][bld][cmp][dl] (unknown size) #> ├─rprojroot #> ├─rstudioapi 0.13 [new][bld][dl] (unknown size) #> └─withr 2.4.2 [new][bld][dl] (unknown size) #> #> Key: [new] new | [dl] download | [bld] build | [cmp] compile
# 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 (+33 dependencies) #> (use `$get_resolution()` to see resolution results) #> (use `$solve()` to solve dependencies)
pd$solve() pd
#> <pkg_dependencies> #> + refs: #> - r-lib/pkgdepends #> + has resolution (+33 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)