-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlinux-binaries.R
47 lines (46 loc) · 2.19 KB
/
linux-binaries.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
# The goal of this function is to speed up installation of dependencies.
# This is done in two ways:
# - Try to get precompiled binaries when available (mainly on ubuntu)
# - Download files in parallel using curl
# The latter can be removed once fixed in base-R: https://github.com/r-devel/r-svn/pull/155
preinstall_linux_binaries <- function(tocheck){
rver <- getRversion()
distro <- system2('lsb_release', '-sc', stdout = TRUE)
options(HTTPUserAgent = sprintf("R/%s R (%s); r-universe (%s)", rver, paste(rver, R.version$platform, R.version$arch, R.version$os), distro))
bioc <- sprintf("https://bioc.r-universe.dev/bin/linux/%s/%s/", distro, substr(rver, 1, 3))
cran <- sprintf("https://p3m.dev/cran/__linux__/%s/latest", distro)
repos <- c(cran, bioc)
db <- utils::available.packages(repos = c(CRAN = cran, BIOC = bioc, official_bioc_repos()))
checkdeps <- unique(unlist(unname(tools::package_dependencies(tocheck, db = db, which = 'most'))))
alldeps <- tools::package_dependencies(checkdeps, db = db, recursive = TRUE)
packages <- unlist(lapply(checkdeps, function(x){
c(rev(alldeps[[x]]), x)
}))
packages <- intersect(unique(packages), row.names(db))
packages <- setdiff(packages, loadedNamespaces())
versions <- db[packages, 'Version']
mirrors <- db[packages, 'Repository']
urls <- sprintf("%s/%s_%s.tar.gz", mirrors, packages, versions)
destdir <- tempfile()
dir.create(destdir)
pwd <- setwd(destdir)
on.exit(setwd(pwd), add = TRUE)
on.exit(unlink(destdir, recursive = TRUE), add = TRUE)
res <- curl::multi_download(urls)
res$ok <- res$success & res$status_code == 200
failures <- res$destfile[!res$ok]
if(length(failures)){
warning("Failed downloads for: ", paste(failures, collapse = ', '))
unlink(failures)
res <- res[res$ok,]
}
utils::install.packages(res$destfile, repos = NULL, Ncpus = parallel::detectCores())
}
official_bioc_repos <- function(){
version <- utils:::.BioC_version_associated_with_R_version()
sprintf(c(
BioCsoft = "https://bioconductor.posit.co/packages/%s/bioc",
BioCann = "https://bioconductor.posit.co/packages/%s/data/annotation",
BioCexp = "https://bioconductor.posit.co/packages/%s/data/experiment"
), version)
}