-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_install_R.R
42 lines (35 loc) · 1.31 KB
/
update_install_R.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
## Create the install.R file dynamically from the project's dependencies
## =====================================================================
## Milan Malfait
## 2022/01/28
## Find all project dependencies
deps <- renv::dependencies()
deps <- unique(deps$Package)
deps <- deps[!(deps %in% c("BiocManager", "renv"))] # don't include these
## Get source repositories from renv.lock file
lock <- jsonlite::read_json("renv.lock")
bioc_ver <- lock$Bioconductor$Version
lock_pkgs <- lock$Packages
pkgs <- lock_pkgs[names(lock_pkgs) %in% deps]
is_gh <- vapply(pkgs, function(x) x$Source == "GitHub", logical(1))
gh_pkgs <- pkgs[is_gh]
gh_pkg_remotes <- vapply(gh_pkgs, function(x) {
sprintf("%s/%s@%s", x$RemoteUsername, x$RemoteRepo, x$RemoteRef)
}, character(1))
to_install <- names(pkgs)
to_install[which(is_gh)] <- gh_pkg_remotes[names(which(is_gh))]
## Write the install.R file
out_file <- file("install.R")
writeLines(
paste(
"## This file is generated by `update_install_R.R`, DO NOT EDIT BY HAND!!!",
'\ninstall.packages(c("remotes", "BiocManager"))',
paste0('BiocManager::install(version = "', bioc_ver, '")'),
"\nBiocManager::install(c(",
paste(" ", sub("(.*)", '"\\1"', to_install), collapse = ",\n"),
"))",
sep = "\n"
),
con = out_file
)
close(out_file)