forked from r-wasm/webr-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.R
37 lines (30 loc) · 968 Bytes
/
install.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
webr_install <- function(packages, repos = "file:/repo", lib = NULL) {
if (is.null(lib)) {
lib <- .libPaths()[[1]]
}
info <- available.packages(repos = repos, type = "source")
deps <- unlist(tools::package_dependencies(packages, info), use.names = FALSE)
deps <- unique(c(packages, deps))
for (dep in deps) {
if (requireNamespace(dep, quietly = TRUE)) {
next
}
ver <- as.character(getRversion())
ver <- gsub("\\.[^.]+$", "", ver)
bin_suffix <- sprintf("bin/emscripten/contrib/%s", ver)
repo <- info[dep, "Repository"]
repo <- sub("src/contrib", bin_suffix, repo, fixed = TRUE)
repo <- sub("file:", "", repo, fixed = TRUE)
pkg_ver <- info[dep, "Version"]
path <- file.path(repo, paste0(dep, "_", pkg_ver, ".tgz"))
tmp <- tempfile()
download.file(path, tmp)
untar(
path,
exdir = lib,
tar = "internal",
extras = "--no-same-permissions"
)
}
invisible(NULL)
}