Skip to content

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

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


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
#> <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
#> ## sysreqs_sudo
#> <default>
#> [1] TRUE
#> 
#> ## build_vignettes
#> <default>
#> [1] FALSE
#> 
#> ## package_cache_dir
#> <default>
#> NULL
#> 
#> ## sysreqs_rspm_repo_id
#> <default>
#> [1] "1"
#> 
#> ## sysreqs_dry_run
#> <default>
#> [1] FALSE
#> 
#> ## metadata_cache_dir
#> <default>
#> [1] "/tmp/Rtmp1EWJjf/file276b199a13b3"
#> 
#> ## dependencies
#> <default>
#> [1] "Depends"   "Imports"   "LinkingTo"
#> 
#> ## sysreqs_rspm_url
#> <default>
#> [1] "https://packagemanager.rstudio.com"
#> 
#> ## sysreqs
#> <default>
#> [1] TRUE
#> 
#> ## platforms
#> <default>
#> [1] "x86_64-pc-linux-gnu-ubuntu-20.04" "source"                          
#> 
#> ## library
#> <set>
#> [1] "/tmp/Rtmp1EWJjf/file276b510382b"
#> 
#> ## metadata_update_after
#> <default>
#> Time difference of 24 hours
#> 
#> ## windows_archs
#> <default>
#> [1] "both"
#> 
#> ## cran_mirror
#> <default>
#>                          CRAN 
#> "https://cloud.r-project.org" 
#> 
#> ## cache_dir
#> <default>
#> [1] "/tmp/Rtmp1EWJjf/file276b2b0d0fa4"
#> 
#> ## sysreqs_verbose
#> <default>
#> [1] TRUE
#> 
#> ## r_versions
#> <default>
#> [1] "4.1.3"
#> 
# Method resolve()
pd <- new_pkg_deps("pak")
pd$resolve()
#> 
#>  Updated metadata database: 3.32 MB in 7 files.
#> 
#>  Updating metadata database
#>  Updating metadata database ... done
#> 
pd$get_resolution()
#> # A data frame: 2 × 30
#>   ref   type     direct directpkg status package version license
#>   <chr> <chr>    <lgl>  <lgl>     <chr>  <chr>   <chr>   <chr>  
#> 1 pak   standard TRUE   TRUE      OK     pak     0.2.1   GPL-3  
#> 2 pak   standard TRUE   TRUE      OK     pak     0.2.1   GPL-3  
#> # … with 22 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>, cache_status <chr>
# Method get_resolution()
pd <- new_pkg_deps("r-lib/pkgdepends")
pd$resolve()
pd$get_resolution()
#> # A data frame: 39 × 30
#>    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.3.1.… MIT + …
#>  2 R6               stand… FALSE  FALSE     OK     R6      2.5.1   MIT + …
#>  3 callr            stand… FALSE  FALSE     OK     callr   3.7.0   MIT + …
#>  4 cli              stand… FALSE  FALSE     OK     cli     3.2.0   MIT + …
#>  5 crayon           stand… FALSE  FALSE     OK     crayon  1.5.1   MIT + …
#>  6 curl             stand… FALSE  FALSE     OK     curl    4.3.2   MIT + …
#>  7 desc             stand… FALSE  FALSE     OK     desc    1.4.1   MIT + …
#>  8 filelock         stand… FALSE  FALSE     OK     filelo… 1.0.2   MIT + …
#>  9 glue             stand… FALSE  FALSE     OK     glue    1.6.2   MIT + …
#> 10 jsonlite         stand… FALSE  FALSE     OK     jsonli… 1.8.0   MIT + …
#> # … with 29 more rows, and 22 more variables: needscompilation <lgl>,
#> #   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>, sysreqs <chr>,
#> #   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 (83):
#>   - select pkgdepends exactly once
#>   - select R6 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 filelock at most once
#>   - select glue at most once
#>   - select jsonlite at most once
#>   ...
#> + solution:
#>   - R6
#>   - callr
#>   - cli
#>   - crayon
#>   - curl
#>   - desc
#>   - filelock
#>   - glue
#>   - jsonlite
#>   - lpSolve
#>   - pkgbuild
#>   - pkgcache
#>   - prettyunits
#>   - processx
#>   - ps
#>   - r-lib/pkgdepends
#>   - rappdirs
#>   - rprojroot
#>   - 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:
#>   - R6
#>   - cli
#>   - crayon
#>   - desc
#>   - glue
#>   - pkgload
#>   - 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 (+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()
#>  [1] "\033[1m\033[3m\033[36mpkgload \033[39m\033[90m1.2.4\033[39m\033[23m\033[22m \033[32m[new][bld][dl] \033[39m\033[90m(62.83 kB)\033[39m"
#>  [2] "├─cli \033[90m3.2.0\033[39m \033[32m[new][bld][cmp][dl] \033[39m\033[90m(493.19 kB)\033[39m"                                          
#>  [3] "│ └─glue \033[90m1.6.2\033[39m \033[32m[new][bld][cmp][dl] \033[39m\033[90m(106.51 kB)\033[39m"                                       
#>  [4] "├─crayon \033[90m1.5.1\033[39m \033[32m[new][bld][dl] \033[39m\033[90m(40.18 kB)\033[39m"                                             
#>  [5] "├─desc \033[90m1.4.1\033[39m \033[32m[new][bld][dl] \033[39m\033[90m(80.67 kB)\033[39m"                                               
#>  [6] "│ ├─cli"                                                                                                                              
#>  [7] "│ ├─R6 \033[90m2.5.1\033[39m \033[32m[new][bld][dl] \033[39m\033[90m(63.42 kB)\033[39m"                                               
#>  [8] "│ └─rprojroot \033[90m2.0.3\033[39m \033[32m[new][bld][dl] \033[39m\033[90m(59.94 kB)\033[39m"                                        
#>  [9] "├─rlang \033[90m1.0.2\033[39m \033[32m[new][bld][cmp][dl] \033[39m\033[90m(724.83 kB)\033[39m"                                        
#> [10] "├─rprojroot"                                                                                                                          
#> [11] "├─rstudioapi \033[90m0.13\033[39m \033[32m[new][bld][dl] \033[39m\033[90m(110.47 kB)\033[39m"                                         
#> [12] "└─withr \033[90m2.5.0\033[39m \033[32m[new][bld][dl] \033[39m\033[90m(102.09 kB)\033[39m"                                             
#> [13] ""                                                                                                                                     
#> [14] "Key:  \033[32m[new]\033[39m new | \033[32m[dl]\033[39m download | \033[32m[bld]\033[39m build | \033[32m[cmp]\033[39m compile"        
#> attr(,"class")
#> [1] "tree"      "character"
# 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 (+19 dependencies)
#> (use `$get_resolution()` to see resolution results)
#> (use `$solve()` to solve dependencies)

pd$solve()
pd
#> <pkg_dependencies>
#> + refs:
#>   - r-lib/pkgdepends
#> + has resolution (+19 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)