Centralised utility functions for covid related projects at Epicentre.
Install covidutils from github with:
remotes::install_github("epicentre-msf/covidutils")
To include a function in the package, add it to a script in the R/
directory.
.R
script inside the R/
directory with an information name, get_ecdc.R
for exampleutils.R
dplyr::filter()
DESCRIPTION
file. This can be done via
usethis::use_package("name_of_package")
devtools::document()
to build the appropriate
documentation filesdevtools::check()
to check the package for any errors or
warningsdevtools::install()
to install or re-install the package
on your systemREADME.Rmd
below then knit the document to produce the .md
format required for githubIf using RStudio, you can document, check and install the package with option in the ‘Build’ pane.
When developing new functions you can run devtools::load_all()
at
anytime load the current state of all function in the R/
directory.
Further R package development resources:
library(tidyverse)
library(covidutils)
df_covid <- get_owid_jhcsse()
glimpse(df_covid)
#> Rows: 84,398
#> Columns: 7
#> $ date <date> 2020-02-24, 2020-02-25, 2020-02-26, 2020-02-27, 2020-02-28,…
#> $ continent <chr> "Asia", "Asia", "Asia", "Asia", "Asia", "Asia", "Asia", "Asi…
#> $ region <chr> "Southern Asia", "Southern Asia", "Southern Asia", "Southern…
#> $ country <chr> "Afghanistan", "Afghanistan", "Afghanistan", "Afghanistan", …
#> $ iso_a3 <chr> "AFG", "AFG", "AFG", "AFG", "AFG", "AFG", "AFG", "AFG", "AFG…
#> $ cases <dbl> 1, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 1, 2, 1, 3, 1, 1, 2, …
#> $ deaths <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
df_trends <- get_country_summaries(df_covid)
glimpse(df_trends)
#> Rows: 190
#> Columns: 53
#> $ continent <chr> "Asia", "Europe", "Africa", "Europe", "Af…
#> $ region <chr> "Southern Asia", "Southern Europe", "Nort…
#> $ country <chr> "Afghanistan", "Albania", "Algeria", "And…
#> $ iso_a3 <chr> "AFG", "ALB", "DZA", "AND", "AGO", "ATG",…
#> $ population <dbl> 38928341, 2877800, 43851043, 77265, 32866…
#> $ cases <dbl> 67743, 132244, 127646, 13671, 33338, 1258…
#> $ deaths <dbl> 2855, 2447, 3440, 127, 742, 42, 75588, 44…
#> $ cases_inc <dbl> 174.01975, 4595.31587, 291.09000, 17693.6…
#> $ deaths_inc <dbl> 7.3339884, 85.0302314, 7.8447393, 164.369…
#> $ date_start_14d <date> 2021-05-11, 2021-05-11, 2021-05-11, 2021…
#> $ date_end_14d <date> 2021-05-24, 2021-05-24, 2021-05-24, 2021…
#> $ cases_14d <dbl> 4212, 462, 2819, 140, 3748, 21, 397014, 2…
#> $ trend_cases_14d <chr> "Likely increasing", "Decreasing", "Incre…
#> $ trend_cases_coeff_14d <dbl> 0.064730659, -0.063993259, 0.035337112, -…
#> $ trend_cases_coeff_lwr95_14d <dbl> -0.0300305835, -0.0854030956, 0.004928549…
#> $ trend_cases_coeff_upr95_14d <dbl> 0.159491902, -0.042583422, 0.065745676, 0…
#> $ trend_cases_preds_14d <list> [<tbl_df[12 x 6]>], [<tbl_df[12 x 6]>], …
#> $ dt_cases_est_14d <dbl> 10.708174, NA, 19.615275, NA, NA, NA, 23.…
#> $ dt_cases_lwr_14d <dbl> 4.345971, NA, 10.542856, NA, NA, NA, 11.4…
#> $ dt_cases_upr_14d <dbl> -23.08138, NA, 140.63919, NA, NA, NA, -90…
#> $ deaths_14d <dbl> 114, 29, 91, 0, 95, 10, 6659, 145, 0, 155…
#> $ cases_inc_14d <dbl> 10.8375675, 16.8243617, 6.4469333, 219.66…
#> $ deaths_inc_14d <dbl> 0.293355407, 1.056241202, 0.208126122, 0.…
#> $ trend_deaths_14d <chr> "Increasing", NA, "Stable", NA, "Likely i…
#> $ trend_deaths_coeff_14d <dbl> 0.0462455276, NA, -0.0007424017, NA, 0.06…
#> $ trend_deaths_coeff_lwr95_14d <dbl> 0.0123976954, NA, -0.0236794925, NA, -0.0…
#> $ trend_deaths_coeff_upr95_14d <dbl> 0.080093360, NA, 0.022194689, NA, 0.14063…
#> $ trend_deaths_preds_14d <list> [<tbl_df[12 x 6]>], <NULL>, [<tbl_df[12 …
#> $ dt_deaths_est_14d <dbl> 14.988415, NA, NA, NA, 9.903671, NA, NA, …
#> $ dt_deaths_lwr_14d <dbl> 8.654240, NA, NA, NA, 4.928621, NA, NA, N…
#> $ dt_deaths_upr_14d <dbl> 55.90936, NA, NA, NA, -1051.30328, NA, NA…
#> $ date_start_30d <date> 2021-04-25, 2021-04-25, 2021-04-25, 2021…
#> $ date_end_30d <date> 2021-05-24, 2021-05-24, 2021-05-24, 2021…
#> $ cases_30d <dbl> 7545, 1806, 6371, 545, 7131, 32, 716263, …
#> $ trend_cases_30d <chr> "Increasing", "Decreasing", "Likely decre…
#> $ trend_cases_coeff_30d <dbl> 0.020014257, -0.060730704, -0.005639469, …
#> $ trend_cases_coeff_lwr95_30d <dbl> 0.0027712747, -0.0693098542, -0.013201830…
#> $ trend_cases_coeff_upr95_30d <dbl> 0.037257239, -0.052151554, 0.001922893, -…
#> $ trend_cases_preds_30d <list> [<tbl_df[28 x 6]>], [<tbl_df[28 x 6]>], …
#> $ dt_cases_est_30d <dbl> 34.63267, NA, NA, NA, 46.68539, NA, 36.74…
#> $ dt_cases_lwr_30d <dbl> 18.60436, NA, NA, NA, 29.36814, NA, 24.53…
#> $ dt_cases_upr_30d <dbl> 250.11854, NA, NA, NA, 113.77279, NA, 73.…
#> $ deaths_30d <dbl> 240, 73, 228, 3, 154, 11, 13006, 393, 0, …
#> $ cases_inc_30d <dbl> 19.411784, 65.735786, 14.569023, 849.7170…
#> $ deaths_inc_30d <dbl> 0.61758833, 2.65877145, 0.52145722, 4.717…
#> $ trend_deaths_30d <chr> "Stable", "Decreasing", "Decreasing", NA,…
#> $ trend_deaths_coeff_30d <dbl> 0.0044184199, -0.0243032375, -0.019043692…
#> $ trend_deaths_coeff_lwr95_30d <dbl> -0.0057519741, -0.0358803712, -0.02415841…
#> $ trend_deaths_coeff_upr95_30d <dbl> 0.014588814, -0.012726104, -0.013928973, …
#> $ trend_deaths_preds_30d <list> [<tbl_df[28 x 6]>], [<tbl_df[28 x 6]>], …
#> $ dt_deaths_est_30d <dbl> NA, NA, NA, NA, 18.40781, NA, 74.13533, N…
#> $ dt_deaths_lwr_30d <dbl> NA, NA, NA, NA, 12.74496, NA, 37.34709, N…
#> $ dt_deaths_upr_30d <dbl> NA, NA, NA, NA, 33.12665, NA, 4954.40056,…
# country with fastest growing case numbers in last 14 days
(iso <- df_trends %>%
filter(trend_cases_coeff_14d == max(trend_cases_coeff_14d, na.rm = TRUE)) %>%
pull(iso_a3))
#> [1] "TWN"
df_country <- df_covid %>% filter(iso_a3 == iso)
df_trends_country <- df_trends %>% filter(iso_a3 == iso)
country_plot(df_country, df_trends_country, add_title = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.