plan.R 8.79 KB
Newer Older
1
2
## Interactive workflow
library(drake)
3
4
5
6
## ## source("packages.R")
## source("src/packages.R")
## ## source("functions.R")
## source("src/functions.R")
7
## ## loadd()
Facundo Muñoz's avatar
Facundo Muñoz committed
8
9

# The workflow plan data frame outlines what you are going to do.
10
plan <- drake_plan(## raw_data = read_excel(
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
    ##   file_in(here("data/..."))
    ## ),
    ## clean_data = raw_data %>% cleanup(),

    ## SOURCE DATA -------------------------------------------------------------

    ## Europe and neighbour countries
    ## EUrope 27 + UK
    eu28 = c("Austria", "Belgium", "Bulgaria", "Croatia",
             "Cyprus", "Czech Republic", "Denmark", "Estonia",
             "Finland", "France", "Germany", "Greece", "Hungary",
             "Ireland", "Italy", "Latvia", "Lithuania", "Luxembourg",
             "Malta", "Netherlands", "Poland", "Portugal",
             "Romania", "Slovakia", "Slovenia", "Spain", "Sweden",
             "United Kingdom"),

    ## European free trade association
    efta = c("Iceland", "Liechtenstein", "Norway", "Switzerland"),

    ## Candidate countries
    candi = c("Albania", "Montenegro", "North Macedonia",
              "Serbia", "Turkey"),

    ## Other countries
    noneu = c("Bosnia and Herzegovina", "Kosovo"),

    ## neighbour countries
    enp = c("Algeria", "Armenia", "Azerbaijan", "Belarus", "Egypt",
            "Georgia", "Israel", "Jordan", "Lebanon", "Libya",
            "Moldova", "Morocco",  "Syria", "Tunisia", "Ukraine"),

42
    wca = c("Cameroon", "Central African Republic", "Chad",
43
44
45
46
47
48
            "Congo DR", "Congo", "Equatorial Guinea", "Gabon",
            "Sao Tome and Principe", "Benin", "Burkina Faso",
            "Cape Verde", "The Gambia", "Ghana", "Guinea",
            "Guinea Bissau", "Côte d'Ivoire", "Liberia", "Mali",
            "Mauritania", "Niger", "Nigeria", "Senegal",
            "Sierra Leone", "Togo"),
49

50
51
52
53
54
55
56
57
58
    ## Total population counts and by Country for 2020 from the WorlPop dtabase
    ## world_population = read.table(
    ##     file_in("https://population.un.org/wpp/Download/Files/1_Indicators%20(Standard)/CSV_FILES/WPP2019_TotalPopulationBySex.csv"),
    ##     header = T,
    ##     sep = ",",
    ##     as.is = T,
    ##     check.names = F,
    ##     quote = "\""
    ## ),
59

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
    ## ECDC Covid19 geographic distribution data
    last_day = Sys.Date() - 1,
    ## string for today
    sdt = format(Sys.Date(),
                 "%d %b %Y"),

    covid = ecdc_covid19(Sys.Date() - 1),

    ## ## String notice for data update
    ## data_update_date = format(Sys.Date() - 1,
    ##                           "%d %b %Y"),

    ## Lock-down dates
    lockdown_dates = read_excel(file_in("data/lockdown.xlsx")) %>%
        transmute(
            name = standardise_country_names(raster::trim(name)),
            lockdown = as.Date(lockdown)
        ),

79
80
81
82
83
84
    ## Coronavirus Government Response Tracker

    ## Governments are taking a wide range of measures in response to
    ## the COVID-19 outbreak.
    ## This tool aims to track and compare
    ## policy responses around the world, rigorously and consistently.
85

86
    lock = stringency(),
87

88
    ## CARTOGRAPHY ---------------------------------------------------
89

90
91
92
93
94
95
96
97
98
99
100
    ## Coordinate Reference Systems
    wgs84 = CRS("+proj=longlat +ellps=WGS84",
                doCheckCRSArgs = FALSE),

    merc = CRS("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext  +no_defs",
               doCheckCRSArgs = FALSE),

    eust = "MOOD has received funding from the EU Horizon 2020 Research and Innovation programme under grant agreement No 874850.",

    ## Country borders and population data
    world_map = get_world_map(ile_in("data/moodgaulcountrywithkos2013wpop.gpkg")),
101

102
103
104
    ## GIS vector layer for European countries (EU 27 + UK + EFTA +
    ## candidate countries + non-EU countries). Source GADM.org
    ## version 3.6
105
    geo_europe_light = geosimplify(
106
107
        world_map[world_map$name %in% xeurope_countries$name, ]
    ),
108

109
110
    roi_europe_light = region_of_interest(
        geo_europe_light, world_map),
111
112

    ## GIS vector layer for West and Central African countries
113
114
    geowca = geosimplify(world_map[world_map$name %in%
                       standardise_country_names(wca),]),
115

116
    roiwca = region_of_interest(geowca, world_map),
117
118
119

    ## DERIVED DATA ----------------------------------------

120
121
122
123
124
125
126
127
128

    world_population = world_map %>%
        as_tibble %>%
        mutate(
            name = standardise_country_names(ADM0_NAME)
        ) %>%
        select(name, pop = TOTPOP) %>%
        filter(pop > 0),

129
130
131
132
133
134
135
136
    ## ## Deaths by country and date
    ## deaths_by_ctry_dt =
    ##   covid %>%
    ##   group_by(date, name) %>%
    ##   summarise(deaths = sum(deaths)) %>%
    ##   ungroup() %>%
    ##   mutate(date = as.Date(date)),

137
    ## Lock-down dates and population counts by country of the european
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
    ## and neighbouring countries
    xeurope_countries =
        enframe(
            list(EU28 = eu28, EFTA = efta, Candidates = candi, Non_EU = noneu),
            name = "group",
            value = "name"
        ) %>%
        unnest(cols = name) %>%
        mutate(
            name = standardise_country_names(name),
            group = fct_inorder(group)
        ) %>%
        select(name, group) %>%
        arrange(name) %>%
        left_join(
            ## Lock-down dates
            lockdown_dates,
            by = "name"
        ) %>%
        left_join(
            ## Population counts in number of people
            world_population,
            by = "name"
        ),
162
163
164
165


    report_euro_html =
        rmarkdown::render(
166
167
168
169
170
171
172
173
174
175
176
177
178
179
            knitr_in("src/Covid19MortalityEurope.Rmd"),
            # knit_root_dir = "../public",  # Is this necessary or convenient?
            output_dir = "public",  # https://github.com/ropensci/drake/issues/742
            output_format =
                rmdformats::readthedown(
                    dev = "png",
                    lightbox = T,
                    gallery = T,
                    use_bookdown = T,
                    number_sections = T),
            output_file =
                file_out("public/covid19MortalityEurope.html"),
            quiet = FALSE
        ),
180
181
182

    report_euro_pdf =
        rmarkdown::render(
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
            knitr_in("src/Covid19MortalityEurope.Rmd"),
            # knit_root_dir = "../public",  # Is this necessary or convenient?
            output_dir = "public",  # https://github.com/ropensci/drake/issues/742
            output_format =
                bookdown::pdf_document2(
                    dev = "pdf",
                    includes = list(
                        in_header = "preamble.tex",
                        before_body = "before_body.tex"),
                    classoption = "a4paper",
                    number_sections = T,
                    latex_engine = "xelatex"
                ),
            output_file = file_out("public/covid19MortalityEurope.pdf"),
            quiet = FALSE
        ),
199
200
201

    report_euro_docx =
        rmarkdown::render(
202
203
204
205
206
207
208
209
210
211
212
            knitr_in("src/Covid19MortalityEurope.Rmd"),
            # knit_root_dir = "../public",  # Is this necessary or convenient?
            output_dir = "public",  # https://github.com/ropensci/drake/issues/742
            output_format =
                bookdown::word_document2(
                    dev = "png",
                    number_sections = T
                ),
            output_file = file_out("public/covid19MortalityEurope.docx"),
            quiet = FALSE
        ),
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229

    ## report_wcafrica_html =
    ##     rmarkdown::render(
    ##                    knitr_in("src/Covid19MortalityWCAfrica.Rmd"),
    ##                    ## knit_root_dir = "../public",  # Is this necessary or convenient?
    ##                    output_dir = "public",  # https://github.com/ropensci/drake/issues/742
    ##                    output_format =
    ##                        rmdformats::readthedown(
    ##                                        toc_depth = 3,
    ##                                        lightbox = T,
    ##                                        gallery = T,
    ##                                        use_bookdown = T,
    ##                                        number_sections = T),
    ##                    output_file = file_out("public/covid19MortalityWCAfrica.html"),
    ##                    quiet = FALSE
    ##                ),

230
    # WEBSITE AND README ------------------------------------------------------
231
232
    readme_md =
        rmarkdown::render(
233
234
235
236
            knitr_in("README.Rmd"),
            output_file = file_out("README.md"),
            quiet = FALSE
        ),
237
238
239
    index_html =
        ## Render to html within public
        rmarkdown::render(
240
241
242
243
244
245
            knitr_in("README.Rmd"),
            output_dir = "public",  # https://github.com/ropensci/drake/issues/742
            output_file = file_out("public/index.html"),
            quiet = FALSE
        ),
)
Facundo Muñoz's avatar
Facundo Muñoz committed
246
247

future::plan(future.callr::callr)