-
Notifications
You must be signed in to change notification settings - Fork 1
/
_targets.R
108 lines (90 loc) · 2.4 KB
/
_targets.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
# Set-up ------------------------------
library(targets)
library(tarchetypes)
tar_option_set(
packages = c("conmat",
"socialmixr",
"countrycode",
"tibble",
"readr",
"dplyr",
"glue",
"fs",
"purrr",
"furrr",
"cli",
"visNetwork")
)
tar_option_set(workspace_on_error = TRUE)
source("R/functions.R")
# Target objects ------------------------------
tar_plan(
# USER: If you would like to use your own population data,
# add it in here instead of the 2015 WPP data.
tar_target(
in_data_wpp,
wpp_age(years = 2015)
),
# Clean issues unique to the wpp_age() data
tar_target(
cleaned_wpp,
in_data_wpp %>%
mutate(country = case_when(
# Renames the following, otherwise picked up as "China"
country == "China, Hong Kong SAR" ~ "Hong Kong",
country == "China, Taiwan province of China" ~ "Taiwan, Province of China",
.default = country
)) %>%
# The following is otherwise picked up as "China"
filter(country != "Less developed regions, excluding China")
),
tar_target(
standardised_wpp_data,
standardise_country_names(
cleaned_wpp,
column_name = "country",
conversion_destination_code = "iso3c")
),
tar_target(
excluded_names,
standardised_wpp_data %>%
filter(is.na(std_country_names)) %>%
select(country) %>%
distinct(country)
),
tar_target(
list_of_data,
split(
standardised_wpp_data,
standardised_wpp_data$std_country_names)
),
# Select the countries you would like to
# generate synthetic contact matrices for
tar_target(
selection_of_countries,
list_of_data[1:200]
# Or alternatively, use dplyr's filter function:
# dplyr::filter(country %in% c("Australia", "New Zealand"))
),
tar_target(
population_data,
create_population_data(selection_of_countries)
),
tar_target(
contact_matrices_data,
create_contact_matrices(
population_data = population_data,
start_age = 0,
end_age = 80
)
),
tar_target(
csv_output,
save_conmat_as_csv(
matrix_list = contact_matrices_data,
path = "./output-contact-matrices",
subfolder = FALSE
),
format = "file"
)
)