plan.R 8.77 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
59
    ## 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 = "\""
    ## ),
    world_population = get_world_pop(),
60

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
    ## 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)
        ),

80
81
82
83
84
85
    ## 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.
86

87
    lock = stringency(),
88

89
    ## CARTOGRAPHY ---------------------------------------------------
90

91
    world_map = get_world_map(),
92

93
94
95
    ## GIS vector layer for European countries (EU 27 + UK + EFTA +
    ## candidate countries + non-EU countries). Source GADM.org
    ## version 3.6
96
    geo_europe_light = geosimplify(
97
98
        world_map[world_map$name %in% xeurope_countries$name, ]
    ),
99

100
101
    roi_europe_light = region_of_interest(
        geo_europe_light, world_map),
102
103

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

107
    roiwca = region_of_interest(geowca, world_map),
108
109
110
111
112
113
114
115
116
117
118
119

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

    ## ## Deaths by country and date
    ## deaths_by_ctry_dt =
    ##   covid %>%
    ##   group_by(date, name) %>%
    ##   summarise(deaths = sum(deaths)) %>%
    ##   ungroup() %>%
    ##   mutate(date = as.Date(date)),

    ## Population counts in thousands of people
120
    pop_countries_2020 = subset(world_population,
121
                                subset = name %in% xeurope_countries$name),
122
123
124
125
126
127
128
129
130
131

    ## ## today (ANSI)
    ## tod = format(Sys.Date(), "%Y%m%d"),

    ## 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),
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
   ## Lock-down dates and population counts by country of the european
    ## 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"
        ),
157
158
159
160
161

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

    report_euro_html =
        rmarkdown::render(
162
163
164
165
166
167
168
169
170
171
172
173
174
175
            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
        ),
176
177
178

    report_euro_pdf =
        rmarkdown::render(
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
            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
        ),
195
196
197

    report_euro_docx =
        rmarkdown::render(
198
199
200
201
202
203
204
205
206
207
208
            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
        ),
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225

    ## 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
    ##                ),

226
    # WEBSITE AND README ------------------------------------------------------
227
228
    readme_md =
        rmarkdown::render(
229
230
231
232
            knitr_in("README.Rmd"),
            output_file = file_out("README.md"),
            quiet = FALSE
        ),
233
234
235
    index_html =
        ## Render to html within public
        rmarkdown::render(
236
237
238
239
240
241
            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
242
243

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