-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_docker.R
56 lines (53 loc) · 1.6 KB
/
update_docker.R
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
library(tidyverse)
available.packages() |>
as.data.frame() |>
transmute(
package = .data$Package, version = .data$Version,
depends = str_replace_all(.data$Depends, "\n", "") |>
str_remove_all("\\s*\\(.*?\\)") |>
str_split(", *"),
imports = str_replace_all(.data$Imports, "\n", "") |>
str_remove_all("\\s*\\(.*?\\)") |>
str_split(", *"),
suggests = str_replace_all(.data$Suggests, "\n", "") |>
str_remove_all("\\s*\\(.*?\\)") |>
str_split(", *")
) -> available
available |>
filter(.data$package == "n2kanalysis") |>
transmute(.data$package, .data$version, level = 0) -> required
available |>
filter(.data$package == "n2kanalysis") |>
select("depends", "imports", "suggests") |>
unlist() |>
sort() -> deps
while (length(deps)) {
available |>
filter(.data$package %in% deps) |>
transmute(.data$package, .data$version, level = max(required$level) + 1) |>
bind_rows(required) -> required
available |>
filter(.data$package %in% deps) |>
select("depends", "imports") |>
unlist() |>
unique() |>
sort() -> deps
}
required |>
group_by(.data$package) |>
slice_max(.data$level, n = 1) |>
ungroup() |>
arrange(desc(.data$level), .data$package) |>
transmute(
cmd = sprintf(
"RUN Rscript -e 'remotes::install_version(\"%s\", version = \"%s\")'",
.data$package, .data$version
)
) |>
pull("cmd") -> mid
docker <- readLines("Dockerfile")
grep("# packages start", docker) |>
head(x = docker) -> before
tail(docker, 1 - grep("# packages end", docker)) -> after
c(before, mid, after) |>
writeLines("Dockerfile")