-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathlistPackages.R
More file actions
25 lines (22 loc) · 845 Bytes
/
listPackages.R
File metadata and controls
25 lines (22 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
library(tidyverse)
local({
files <- dir(pattern = glob2rx("*.Rmd"))
code <- lapply(files, read_lines) %>% unlist
r <- regexec("^library\\((.*?)\\)", code, perl = TRUE)
m <- regmatches(code, r)
u <- sapply(m, length) > 0
pkgs1 <- sapply(m[u], function(x) x[2])
r <- regexec("([A-Za-z]+)::.*", code, perl = TRUE)
m <- regmatches(code, r)
u <- sapply(m, length) > 0
pkgs2 <- sapply(m[u], function(x) x[2])
pkgs <- unique(c(pkgs1, pkgs2)) %>% sort
write_lines(pkgs, "_R_package_list.txt")
int <- installed.packages()[, 1]
ava <- available.packages() %>% rownames
need <- setdiff(pkgs, int)
need <- need[need %in% ava]
if(length(need) > 0L) {
install.packages(need)
}
})