-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.R
65 lines (58 loc) · 2.06 KB
/
build.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
# Rebuild the package from scratch
library(devtools)
library(testthat)
library(rmarkdown)
source_subprocess <- function(source_file, ...) {
system2(command = "Rscript", args = source_file, ...)
}
# Internal data ----------------------------------------------------------------
# Run "data-raw/request-naaccr-info.R" to update the file
# "data-raw/naaccr_info_from_api.csv". Because of our proxy, the script is not
# reliable enough to include in an automated build.
if (dir.exists("data")) {
unlink("data", recursive = TRUE)
}
dir.create("data")
if (dir.exists("data-raw/sys-data")) {
unlink("data-raw/sys-data", recursive = TRUE)
}
dir.create("data-raw/sys-data")
data_scripts <- list.files("data-raw", "^create-.*\\.R$", full.names = TRUE)
for (script in data_scripts) {
source_subprocess(script)
}
sys_data_files <- list.files("data-raw/sys-data", full.names = TRUE)
sys_objects <- new.env()
for (sdf in sys_data_files) {
load(sdf, envir = sys_objects)
}
save(
list = names(sys_objects), envir = sys_objects, file = "R/sysdata.rda",
version = 2, compress = "xz"
)
# Tests ------------------------------------------------------------------------
results <- devtools::test()
results_df <- as.data.frame(results)
if (any(results_df[["failed"]] > 0 | results_df[["error"]] > 0)) {
stop("Testing failed")
}
# Build ------------------------------------------------------------------------
devtools::document()
old_opts <- options(width = 80)
rmarkdown::render("README.Rmd")
options(old_opts)
description <- readLines("DESCRIPTION")
description <- description[!startsWith(tolower(description), "roxygen")]
writeLines(description, "DESCRIPTION")
built_path <- devtools::build(binary = FALSE)
devtools::build(binary = TRUE)
check_results <- devtools::check_built(built_path)
if (length(check_results[["notes"]])) {
message(paste0(check_results[["notes"]], collapse = "\n\n"))
}
if (length(check_results[["warnings"]])) {
warning(paste0(check_results[["errors"]], collapse = "\n\n"))
}
if (length(check_results[["errors"]])) {
stop(paste0(check_results[["errors"]], collapse = "\n\n"))
}