-
Notifications
You must be signed in to change notification settings - Fork 1
/
z-run-all.R
69 lines (47 loc) · 1.44 KB
/
z-run-all.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
61
62
63
64
65
66
67
68
69
library(callr)
library(fs)
library(purrr)
FULL_RECREATE <- FALSE
PACKAGES_UPGRADE <- FALSE
## Lock package versions ----
# get packages used in project folder
deps <- unique(renv::dependencies()[["Package"]])
if (PACKAGES_UPGRADE) {
pak::pkg_install(deps, ask = FALSE, upgrade = TRUE)
}
# create lock file of versions for all packages
pak::lockfile_create(deps)
## Format and check code ----
# format project code with tidyverse style guide
styler::style_dir(exclude_dirs = c(".cache", "renv"))
# check code style, syntax errors and semantic issues
lintr::lint_dir()
## Run all scripts ----
# remove folder with data created in project
if (FULL_RECREATE && dir_exists("data")) {
dir_delete("data")
}
# run R scripts in subfolders
r_files <- dir_ls(".", glob = "*.R", recurse = 1)
r_files <- r_files[r_files != "z-run-all.R"]
if (!FULL_RECREATE) { # ignore time intense files
r_files <- r_files[!r_files %in% c("01-ess-prt.R", "07-parlgov-ess_cabinets.R")]
}
map(r_files, rscript)
dir_ls("data/")
## Render notebooks ----
dir_delete("figures-tables/")
dir_create("figures-tables/")
# render Quarto project
if (FULL_RECREATE) {
map(c("_book/", "_freeze/"), \(.dir) if (dir_exists(.dir)) dir_delete(.dir))
}
system("quarto render")
# remove Rplots created with print()
if (file_exists("Rplots.pdf")) {
file_delete("Rplots.pdf")
}
## Log session info ----
# add session info: R version, tidyverse packages, platform
library(tidyverse)
sessionInfo()