Download and install R packages, with their dependencies, from various sources.

new_pkg_installation_proposal(refs, config = list(), ...)

Arguments

refs

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

config

Configuration options, a named list. See 'Configuration'. If it does not include library, then .libPaths()[1] is added as library.

...

Additional arguments, passed to pkg_installation_proposal$new().

Value

new_pkg_installation_proposal() returns a new pkg_installation_proposal object.

Details

new_pkg_installation_proposal() creates a new object from the pkg_installation_proposal class. The advantage of new_pkg_installation_proposal() compared to using the pkg_installation_proposal constructor directly is that it avoids making pkgdepends a build time dependency.

Typical workflow to install a set of packages:

  1. Create a pkg_installation_proposal object with new_pkg_installation_proposal().

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

  3. Solve the package dependencies, to get an installation plan, with pkg_installation_proposal$solve().

  4. Download all files with pkg_installation_proposal$download().

  5. Install the downloaded files with pkg_installation_proposal$install().

Methods

Public methods


Method new()

Create a new pkg_installation_proposal object. Consider using new_pkg_installation_proposal() instead of calling the constructor directly.

The returned object can be used to look up (recursive) dependencies of R packages from various sources, and then download and install the package files.

Usage

pkg_installation_proposal$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'. It needs to include the package library to install to, in library.

policy

Solution policy. See 'The dependency solver'.

remote_types

Custom remote ref types, this is for advanced use, and experimental currently.


Method get_refs()

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

Usage

pkg_installation_proposal$get_refs()

Returns

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


Method get_config()

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

Usage

pkg_installation_proposal$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_installation_proposal$resolve()

Returns

The pkg_installation_proposal object, invisibly.


Method async_resolve()

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

Usage

pkg_installation_proposal$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_installation_proposal$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_installation_proposal$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_installation_proposal$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.

Usage

pkg_installation_proposal$solve()

Returns

The pkg_installation_proposal object itself, invisibly.


Method get_solution()

Returns the solution of the package dependencies.

Usage

pkg_installation_proposal$get_solution()

Returns

A pkg_solution_result object, which is a list. See pkg_solution_result for details.


Method show_solution()

Show the solution on the screen.

Usage

pkg_installation_proposal$show_solution(key = FALSE)

Arguments

key

Whether to show the key to the package list annotation.

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_installation_proposal$stop_for_solution_error()


Method create_lockfile()

Create a lock file that contains the information to perform the installation later, possibly in another R session.

Usage

pkg_installation_proposal$create_lockfile(path = "pkg.lock", version = 1)

Arguments

path

Name of the lock file. The default is pkg.lock in the current working directory.

version

Only version 1 is supported currently.

Details

Note, since the URLs of CRAN and most CRAN-like repositories change over time, in practice you cannot perform the plan of the lock file much later. For example, binary packages of older package version are removed, and won't be found.

Similarly, for url:: remote types, the URL might hold an updated version of the package, compared to when the lock file was created. Should this happen, pkgdepends prints a warning, but it will try to continue the installation. The installation might fail if the updated package has different (e.g. new) dependencies.

Currently the intended use case of lock files in on CI systems, to facilitate caching. The (hash of the) lock file provides a good key for caching systems.


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_installation_proposal$draw()

Returns

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


Method download()

Download all packages that are part of the solution. It uses the package cache in the pkgcache package by default, to avoid downloads if possible.

Usage

pkg_installation_proposal$download()

Returns

The pkg_installation_proposal object itself, invisibly.


Method async_download()

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

Usage

pkg_installation_proposal$async_download()

Returns

A deferred value.


Method get_downloads()

Returns the summary of the package downloads.

Usage

pkg_installation_proposal$get_downloads()

Returns

A pkg_download_result object, which is a list. See pkg_download_result for details.


Method stop_for_download_error()

Throw and error if the some of the downloads have failed for the most recent pkg_installation_proposal$download() call.

Usage

pkg_installation_proposal$stop_for_download_error()


Method install()

Install the downloaded packages. It calls install_package_plan().

Usage

pkg_installation_proposal$install()

Returns

The return value of install_package_plan(). Create an installation plan for the downloaded packages.


Method get_install_plan()

Usage

pkg_installation_proposal$get_install_plan()

Returns

An installation plan, see 'Installation plans' for the format.


Method format()

Format a pkg_installation_proposal object, typically for printing.

Usage

pkg_installation_proposal$format(...)

Arguments

...

not used currently.

Returns

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


Method print()

Prints a pkg_installation_proposal object to the screen.

The printout includes:

  • The package refs.

  • The policy of the dependency solver.

  • Whether the object has the solved dependencies.

  • Whether the solution had errors.

  • Whether the object has downloads.

  • Whether the downloads had errors.

  • Advice on which methods to call next.

See the example below.

Usage

pkg_installation_proposal$print(...)

Arguments

...

not used currently.

Returns

The pkg_installation_proposal object itself, invisibly.


Method clone()

The objects of this class are cloneable with this method.

Usage

pkg_installation_proposal$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

if (FALSE) { pdi <- new_pkg_installation_proposal( "pak", config = list(library = tempfile()) ) pdi pdi$resolve() pdi pdi$solve() pdi pdi$download() pdi } pdi <- new_pkg_installation_proposal( "r-lib/pkgdepends", config = list(library = tempfile()))
#> Creating library directory: /tmp/RtmpReCZ7Q/file2d4a4f9dad90
pdi
#> <pkg_installation_proposal> #> + refs: #> - r-lib/pkgdepends #> + solution policy: lazy #> (use `$solve()` to solve dependencies)
pdi <- new_pkg_installation_proposal("r-lib/pkgdepends") pdi$get_refs()
#> [1] "r-lib/pkgdepends"
pdi <- new_pkg_installation_proposal( "pak", config = list(library = tempfile()) )
#> Creating library directory: /tmp/RtmpReCZ7Q/file2d4a2cb6eca3
pdi$get_config()
#> + config: #> - library: /tmp/RtmpReCZ7Q/file2d4a2cb6eca3 #> - cache_dir: /tmp/RtmpReCZ7Q/file2d4a3380bdee #> - package_cache_dir: <default> #> - metadata_cache_dir: /tmp/RtmpReCZ7Q/file2d4a7b24b7c2 #> - 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
if (FALSE) { pdi <- new_pkg_installation_proposal( "pak", config = list(library = tempfile()) ) pdi$resolve() pdi$get_resolution() } if (FALSE) { pdi <- new_pkg_installation_proposal( "r-lib/pkgdepends", config = list(library = tempfile()) ) pdi$resolve() pdi$get_resolution() } pdi <- new_pkg_installation_proposal( "r-lib/pkgdepends", config = list(library = tempfile()) )
#> Creating library directory: /tmp/RtmpReCZ7Q/file2d4a1336adf1
pdi$get_solve_policy()
#> [1] "lazy"
pdi$set_solve_policy("upgrade") pdi$get_solve_policy()
#> [1] "upgrade"
pdi <- new_pkg_installation_proposal( "r-lib/pkgdepends", config = list(library = tempfile()) )
#> Creating library directory: /tmp/RtmpReCZ7Q/file2d4a6ec55939
pdi$get_solve_policy()
#> [1] "lazy"
pdi$set_solve_policy("upgrade") pdi$get_solve_policy()
#> [1] "upgrade"
if (FALSE) { pdi <- new_pkg_installation_proposal( "r-lib/pkgdepends", config = list(library = tempfile()) ) pdi$resolve() pdi$solve() pdi$get_solution() } if (FALSE) { pdi <- new_pkg_installation_proposal( "r-lib/pkgdepends", config = list(library = tempfile()) ) pdi$resolve() pdi$solve() pdi$get_solution() } if (FALSE) { pdi <- new_pkg_installation_proposal( "r-lib/pkgdepends", config = list(library = tempfile()) ) pdi$resolve() pdi$solve() pdi$get_solution() pdi$show_solution() } if (FALSE) { # This is an error, because the packages conflict: pdi <- new_pkg_installation_proposal( c("r-lib/pak", "cran::pak"), config = list(library = tempfile()) ) pdi$resolve() pdi$solve() pdi # This fails: # pdi$stop_for_solution_error() } if (FALSE) { pdi <- new_pkg_installation_proposal( "pak", config = list(library = tempfile()) ) pdi$resolve() pdi$solve() pdi$draw() } if (FALSE) { pdi <- new_pkg_installation_proposal( c("r-lib/pak", "cran::pak"), config = list(library = tempfile()) ) pdi$resolve() pdi$solve() pdi$download() pdi$get_downloads() } if (FALSE) { pdi <- new_pkg_installation_proposal( c("r-lib/pak", "cran::pak"), config = list(library = tempfile()) ) pdi$resolve() pdi$solve() pdi$download() pdi$get_downloads() } if (FALSE) { pdi <- new_pkg_installation_proposal( "pak", config = list(library = tempfile()) ) pdi$resolve() pdi$solve() pdi$download() pdi$get_install_plan() } # Method print pdi <- new_pkg_installation_proposal( "pak", config = list(library = tempfile()) )
#> Creating library directory: /tmp/RtmpReCZ7Q/file2d4a5ebc31af
pdi
#> <pkg_installation_proposal> #> + refs: #> - pak #> + solution policy: lazy #> (use `$solve()` to solve dependencies)
pdi$resolve() pdi
#> <pkg_installation_proposal> #> + refs: #> - pak #> + solution policy: lazy #> (use `$solve()` to solve dependencies)
pdi$solve() pdi
#> <pkg_installation_proposal> #> + refs: #> - pak #> + solution policy: lazy #> + has solution #> (use `$download()` to download packages) #> (use `$show_solution()` to see the packages to install #> (use `$get_solution()` to see the full solution results) #> (use `$draw()` to draw the dependency tree) #> (use `$create_lockfile()` to write a lock file)
pdi$download()
#> Getting 42 pkgs with unknown sizes
#> Cached copy of R6 2.5.0 (source) is the latest build
#> Cached copy of assertthat 0.2.1 (source) is the latest build
#> Cached copy of callr 3.7.0 (source) is the latest build
#> Cached copy of cli 2.5.0 (source) is the latest build
#> Cached copy of crayon 1.4.1 (source) is the latest build
#> Cached copy of curl 4.3.2 (source) is the latest build
#> Cached copy of desc 1.3.0 (source) is the latest build
#> Cached copy of digest 0.6.27 (source) is the latest build
#> Cached copy of ellipsis 0.3.2 (source) is the latest build
#> Cached copy of fansi 0.5.0 (source) is the latest build
#> Cached copy of filelock 1.0.2 (source) is the latest build
#> Cached copy of glue 1.4.2 (source) is the latest build
#> Cached copy of jsonlite 1.7.2 (source) is the latest build
#> Cached copy of lifecycle 1.0.0 (source) is the latest build
#> Cached copy of lpSolve 5.6.15 (source) is the latest build
#> Cached copy of magrittr 2.0.1 (source) is the latest build
#> Cached copy of pillar 1.6.1 (source) is the latest build
#> Cached copy of pkgbuild 1.2.0 (source) is the latest build
#> Cached copy of pkgcache 1.2.2 (source) is the latest build
#> Cached copy of pkgconfig 2.0.3 (source) is the latest build
#> Cached copy of prettyunits 1.1.1 (source) is the latest build
#> Cached copy of processx 3.5.2 (source) is the latest build
#> Cached copy of ps 1.6.0 (source) is the latest build
#> Cached copy of rappdirs 0.3.3 (source) is the latest build
#> Cached copy of rematch2 2.1.2 (source) is the latest build
#> Cached copy of rlang 0.4.11 (source) is the latest build
#> Cached copy of rprojroot 2.0.2 (source) is the latest build
#> Cached copy of tibble 3.1.2 (source) is the latest build
#> Cached copy of utf8 1.2.1 (source) is the latest build
#> Cached copy of uuid 0.1-4 (source) is the latest build
#> Cached copy of vctrs 0.3.8 (source) is the latest build
#> Cached copy of withr 2.4.2 (source) is the latest build
#> Got hms 1.1.0 (source) (97.81 kB)
#> Got stringr 1.4.0 (source) (204.52 kB)
#> Got progress 1.2.2 (source) (83.00 kB)
#> Got xml2 1.3.2 (source) (617.91 kB)
#> Got cliapp 0.1.1 (source) (233.41 kB)
#> Got stringi 1.6.2 (source) (2.94 MB)
#> Got prettycode 1.1.0 (source) (242.29 kB)
#> Got base64enc 0.1-3 (source) (38.95 kB)
#> Got selectr 0.4-2 (source) (488.96 kB)
#> Got pak 0.1.2.1 (source) (403.65 kB)
pdi
#> <pkg_installation_proposal> #> + refs: #> - pak #> + solution policy: lazy #> + has solution #> + has downloads #> (use `$show_solution()` to see the packages to install #> (use `$get_solution()` to see the full solution results) #> (use `$draw()` to draw the dependency tree) #> (use `$create_lockfile()` to write a lock file) #> (use `$get_downloads()` to get download data) #> (use `$get_install_plan()` to get the installation plan) #> (use `$install()` to install the packages)