-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.R
60 lines (53 loc) · 2.03 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
## Usage: move it inside /usr/local/bin
## default uses the DESCRIPTION file from the current directory
## Install versioned packages: uses VersionedPackages field in DESCRIPTION
## VersionedPackages: devtools (1.11.0), mypackage (>= 1.12.0, < 1.14)
## R -q -e 'source("/usr/local/bin/install.R"); install$versioned()'
## List libraries listed in the SystemRequirements field of DESCRIPTION
## concatenated and saved into requirements.txt
## R -q -e 'source("/usr/local/bin/install.R"); install$sysreqs()'
## LIBS=$(cat requirements.txt); rm requirements.txt
install <- local({
## list SystemRequirements separated by space
sysreqs <- function(pkgdir = ".", file="requirements.txt") {
descr <- as.list(as.data.frame(read.dcf(paste0(pkgdir, "/DESCRIPTION"))))
if (!is.null(descr$SystemRequirements)) {
out <- trimws(strsplit(descr$SystemRequirements, ",")[[1]])
out <- paste(out, collapse=" ")
} else {
out <- ""
}
writeLines(out, paste0(pkgdir, "/", file))
}
## install versioned packages listed in VersionedPackages
## ... passes args to remotes::install_version
versioned <- function(pkgdir = ".", ...) {
descr <- as.list(as.data.frame(read.dcf(paste0(pkgdir, "/DESCRIPTION"))))
if (!is.null(descr$VersionedPackages)) {
h <- function(x) {
x <- gsub("<", "< ", x)
x <- gsub(">", "> ", x)
x <- gsub("< =", "<= ", x)
x <- gsub("> =", ">= ", x)
x <- gsub("<=", "<= ", x)
x <- gsub(">=", ">= ", x)
x <- gsub(" ", " ", x)
x
}
pkgs <- gsub("[[:space:]]", "", descr$VersionedPackages)
pkgs <- strsplit(pkgs, "),", fixed=TRUE)[[1]]
pkgs <- gsub(")", "", pkgs, fixed=TRUE)
pkgs <- strsplit(pkgs, "(", fixed=TRUE)
for (i in seq_along(pkgs)) {
pkgs[[i]][2L] <- gsub(",", ", ", pkgs[[i]][2L])
pkgs[[i]][2L] <- h(pkgs[[i]][2L])
}
lapply(pkgs, function(z) remotes::install_version(z[1L], z[2L], ...))
}
invisible(NULL)
}
list(
versioned = versioned,
sysreqs = sysreqs
)
})