-
Notifications
You must be signed in to change notification settings - Fork 1
/
directories.R
94 lines (71 loc) · 2.76 KB
/
directories.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
###########################################################
# SET DIRECTORIES
#
# Set and get directories in one place in the name of consistency
# and ease. Creates any directories that do not currently exist.
#
# OUTPUTS:
# - A list of relevant directories (within o$pth) which can
# be referenced throughout in the pipeline
#
###########################################################
# ---------------------------------------------------------
# Define paths for project inputs and outputs
# ---------------------------------------------------------
prepare_dirs = function(o) {
# Initiate list with reference to main code directory
#
# NOTE: We should already be in this code directory
pth = list(code = getwd())
# ---- Input and configuration directories ----
# Parent path of all input files
pth$input = file.path(pth$code, "input")
pth$config = file.path(pth$code, "config")
# Paths to VIMC and Gapminder inputs
pth$vimc = file.path(pth$input, "vimc")
pth$gapminder = file.path(pth$input, "gapminder")
# Parent path of all external model output files
pth$extern = file.path(pth$code, "extern")
pth$template = file.path(pth$extern, "template")
# ---- Output directories ----
# Parent path of all output files
pth$output = file.path(pth$code, "output")
# Path to cached data tables
pth$tables = file.path(pth$output, "0_tables")
# Path to static model assumptions and results
pth$static = file.path(pth$output, "1_static")
pth$static_d = file.path(pth$static, "disease")
pth$static_v = file.path(pth$static, "vaccine")
pth$static_t = file.path(pth$static, "vaccine_type")
# Path to imputation and impact function files
pth$impute = file.path(pth$output, "2_impute")
pth$impact = file.path(pth$output, "3_impact")
# Path to figures and other output results
pth$history = file.path(pth$output, "4_history")
pth$infer = file.path(pth$output, "5_infer")
# Path to relative risk and impact factor files
# pth$uncertainty = file.path(pth$output, "6_uncertainty")
# Path to all figures
pth$figures = file.path(pth$output, "6_figures")
# Append paths to o list
o = set_dirs(o, pth)
return(o)
}
# ---------------------------------------------------------
# Make all output directories and append to o list
# ---------------------------------------------------------
set_dirs = function(o, pth) {
# Iterate through dirs
for (pth_name in names(pth)) {
this_pth = pth[[pth_name]]
# If it does not already exist, create it
if (!dir.exists(this_pth)) {
dir.create(this_pth, recursive = TRUE)
}
# Add a file separator to end of dir path
pth[[pth_name]] = paste0(this_pth, file_sep())
}
# Append to o list
o$pth = pth
return(o)
}