forked from WorldHealthOrganization/epi50-vaccine-impact
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.R
132 lines (97 loc) · 3.22 KB
/
options.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
###########################################################
# OPTIONS
#
# Set key options for all things model related. The output
# of this function, o (a list), lives in the global
# environment, so can be referenced throughout the pipeline.
#
###########################################################
# ---------------------------------------------------------
# Set model options and assumptions
# ---------------------------------------------------------
set_options = function(run_module = NA) {
message("* Setting options")
# Several global R settings to make life easier
default_R_options() # See auxiliary.R
# Initiate options list
o = list(run_module = run_module)
# Prepare output directory system
o = prepare_dirs(o) # See directories.R
# Convert config yaml files to datatables
o = parse_general_options(o)
# ---- Parallelisation settings ----
# Detect number of cores available to this user
o$n_cores = detectCores()
# Use multiple cores to speed up several processes
#
# NOTE: Not available on windows - flags ignored
o$parallel = list(
interp = TRUE,
impute = TRUE,
impact = FALSE, # NOTE: Having issues with shared memory
history = TRUE)
# Apply parallelisation depending on operating system
o = set_parallel(o)
# ---- Loading flags ----
# Flag to force (re)download Gapminder data from github
o$force_download_gapminder = FALSE
# ---- Simulation flags ----
# Directly simulate Dynamice model
o$simulate_dynamice = FALSE
# ---- Plotting flags ----
# Turn figures on or off
o$plot_inputs = TRUE
o$plot_static = TRUE
o$plot_imputation = TRUE
o$plot_impact = TRUE
o$plot_history = TRUE
# Main results table
o$results_table = TRUE
# ---- Plotting settings ----
# Saved figure size
o$save_width = 14
o$save_height = 10
# Units of figures sizes
o$save_units = "in"
# Plotting resolution (in dpi)
o$save_resolution = 300
# Image format for saving figure
#
# NOTE: Use a character vector to save with multiple formats at once
o$figure_format = "png"
o$manuscript_format = "svg" # Lancet requires: "eps" or "svg"
return(o)
}
# ---------------------------------------------------------
# Apply (or trivalise) parallelisation depending on operating system
# ---------------------------------------------------------
set_parallel = function(o) {
# Auto turn off parallelisation on Windows
if (.Platform$OS.type == "windows")
o$parallel[] = FALSE
return(o)
}
# ---------------------------------------------------------
# Load and parse general options from config/general yaml
# ---------------------------------------------------------
parse_general_options = function(o) {
# Function to parse general inputs
parse_fn = function(exp) {
# Attempt to evaluate expression
value = tryCatch(
eval_str(exp),
error = function(e) exp)
# Do not interpret strings as functions
if (is.function(value))
value = exp
return(value)
}
# Load general options
general = o$pth$config %>%
paste0("general.yaml") %>%
read_yaml() %>%
lapply(parse_fn)
# Append to global options list
o = c(o, general)
return(o)
}