-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate_reports.R
74 lines (51 loc) · 1.93 KB
/
generate_reports.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
70
71
72
73
74
# Notes -------------------------------------------------------------------
#
# Initialisation ----------------------------------------------------------
rm(list = ls()) # Clear Workspace (better to restart the session)
source(here::here("analysis", "00_init.R"))
library(foreach)
library(doParallel)
render_fit <- FALSE
render_perf <- FALSE
render_parallel <- function(input, rpt, ...) {
n_cluster <- min(nrow(rpt), parallel::detectCores() - 2)
cl <- makeCluster(n_cluster, outfile = "")
registerDoParallel(cl)
foreach(i = 1:nrow(rpt)) %dopar% {
tryCatch({
tf <- tempfile()
dir.create(tf)
rmarkdown::render(
input = input,
params = rpt$Parameter[[i]],
output_file = rpt$OutputFile[i],
output_dir = here::here("docs"),
intermediates_dir = tf,
...
)
unlink(tf)
}, error = function(e) {
cat(glue::glue("Error in rpt row {i}"), sep = "\n")
})
NULL
}
stopCluster(cl)
NULL
}
# Fit ---------------------------------------------------------------------
if (render_fit) {
rpt <- available_models() %>%
expand_grid(Dataset = c("Derexyl", "PFDC", "Fake")) %>%
mutate(Parameters = pmap(list(score = Score, dataset = Dataset, model = Model), list),
OutputFile = glue::glue("fit_{Score}_{Model}_{Dataset}.html"))
render_parallel(input = here::here("analysis", "03_check_fit.Rmd"), rpt = rpt, quiet = TRUE)
}
# Performance -------------------------------------------------------
if (render_perf) {
rpt <- expand_grid(score = detail_POSCORAD()$Name,
dataset = c("Derexyl", "PFDC", "Fake"),
t_horizon = 4) %>%
mutate(Parameters = pmap(list(score = score, dataset = dataset, t_horizon = t_horizon), list),
OutputFile = glue::glue("perf{t_horizon}_{score}_{dataset}.html"))
render_parallel(input = here::here("analysis", "05_check_performance.Rmd"), rpt = rpt, quiet = TRUE)
}