/
pkgdepends-how-to.Rmd
121 lines (99 loc) · 2.21 KB
/
pkgdepends-how-to.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
---
title: "pkgdepends HOWTO"
output:
rmarkdown::html_document:
toc: true
toc_depth: 2
---
```{r, include = FALSE, cache = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
out.width = "100%",
cache = TRUE,
eval = TRUE
)
```
```{r, include = FALSE, cache = FALSE}
# Turn on ANSI colors
options(
crayon.enabled = TRUE,
crayon.colors = 256)
crayon::num_colors(forget = TRUE)
asciicast::init_knitr_engine(
startup = quote({
set.seed(1) }),
echo = TRUE,
echo_input = FALSE)
```
# Dependencies
## How to list all dependencies of a CRAN/Bioconductor package?
```{asciicast}
library(pkgdepends)
prop <- new_pkg_deps("ggplot2")
prop$solve()
prop$get_solution()$data
```
You can also draw a dependency tree:
```{asciicast}
prop$draw()
```
## How to list all dependencies of a GitHub package?
```{asciicast}
library(pkgdepends)
prop <- new_pkg_deps("tidyverse/ggplot2")
prop$solve()
prop$get_solution()$data
```
## How to list all dependencies of a local package?
```{asciicast}
library(pkgdepends)
prop <- new_pkg_deps("local::.")
prop$solve()
prop$get_solution()$data
```
# Downloads
## How to download a package and all of its dependencies?
```{asciicast}
library(pkgdepends)
target_dir <- tempfile()
dir.create(target_dir)
prop <- new_pkg_download_proposal("ggplot2", config = list(cache_dir = target_dir))
prop$resolve()
prop$download()
prop$get_downloads()
dir(target_dir)
```
# Installation
## How to install a package into a new library?
```{asciicast}
library(pkgdepends)
dir.create(new_lib <- tempfile())
prop <- new_pkg_installation_proposal("pkgconfig", config = list(library = new_lib))
prop$solve()
prop$download()
prop$install()
lib_status(new_lib)
```
## How to update a package?
Install an older version first.
```{asciicast}
library(pkgdepends)
dir.create(new_lib <- tempfile())
config <- list(library = new_lib)
prop <- new_pkg_installation_proposal("cran/pkgconfig@2.0.2", config = config)
prop$solve()
prop$download()
prop$install()
lib_status(new_lib)
```
Now update.
```{asciicast}
library(pkgdepends)
prop2 <- new_pkg_installation_proposal("pkgconfig", config = config)
prop2$set_solve_policy("upgrade")
prop2$solve()
prop2$download()
prop2$install()
lib_status(new_lib)
```