pkg_deps: R6 class for package dependency lookup

new_pkg_depsR Documentation

R6 class for package dependency lookup

Description

Look up dependencies of R packages from various sources.

Usage

new_pkg_deps(refs, ...)

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:

  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.

Value

new_pkg_deps() returns a new pkg_deps object.

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

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.

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

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


# Method get_refs()
pd <- new_pkg_deps(c("pak", "jsonlite"))
pd$get_refs()


# Method get_config()
pd <- new_pkg_deps("pak")
pd$get_config()


# Method resolve()
pd <- new_pkg_deps("pak")
pd$resolve()
pd$get_resolution()


# Method get_resolution()
pd <- new_pkg_deps("r-lib/pkgdepends")
pd$resolve()
pd$get_resolution()


# Method get_solve_policy()
pdi <- new_pkg_deps("r-lib/pkgdepends")
pdi$get_solve_policy()
pdi$set_solve_policy("upgrade")
pdi$get_solve_policy()


# Method set_solve_policy()
pdi <- new_pkg_deps("r-lib/pkgdepends")
pdi$get_solve_policy()
pdi$set_solve_policy("upgrade")
pdi$get_solve_policy()


# Method solve()
pd <- new_pkg_deps("r-lib/pkgdepends")
pd$resolve()
pd$solve()
pd$get_solution()


# Method get_solution()
pd <- new_pkg_deps("pkgload")
pd$resolve()
pd$solve()
pd$get_solution()


# 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
# This fails:
# pd$stop_for_solution_error()


# Method draw()
pd <- new_pkg_deps("pkgload")
pd$solve()
pd$draw()


# Method print()
pd <- new_pkg_deps("r-lib/pkgdepends")
pd

pd$resolve()
pd

pd$solve()
pd


pkgdepends documentation built on Nov. 10, 2023, 5:06 p.m.