knitr::opts_chunk$set( collapse = TRUE, warning = FALSE, message = FALSE, comment = "#>" ) library(SaviR) library(dplyr) library(tidyr) library(ggplot2) sunday_date <- lubridate::floor_date(Sys.Date(), "week", week_start = 7)
SaviR version 0.2 brings some major revisions to the SaviR API design; some complementary and some breaking. I'll highlight a few of them below.
This will have a pretty substantial impact on all products, and will likely break most existing downstream code...
All data pull functions use different naming schemes for ISO country codes and country names. It's never apparent which column to join on, and after joining, it's very difficult to reason what came from where. I'm attempting to standardize all ISO code columns to either iso2code or id (iso3code) depending on their value.
There should be no guesswork involved when joining disparate datasets (it's always id or iso2code, and they should join without specifying a by
argument).
iso_code
-> id
iso_code
-> idcountry_code
-> iso2code
who_region
, region
onetable
, and get_covid_df()
is never used without joining to this metadata table iso_code
-> id
location
-> owid_country
get_vax_manufacturers()
changedonetable
head(get_covid_df("WHO"))
head(get_vax())
get_combined_table()
Many scripts accomplished this task differently, and it was never clear to most exactly how to pull and join these data together.
No one is forced to use it, but there is now an automated way to:
get_combined_table()
takes two arguments:
who_data <- get_combined_table("WHO") # is identical to the following sequence: # (which still works, but is unnecessary) # onetable %>% # select(-geometry) %>% # In the case that geometry = FALSE # right_join(get_covid_df(), by = "iso2code") %>% # filter(source == "WHO") %>% # In the case of type = "WHO" # # filter(!(country == "China" & source == "WHO")) %>% # In the case of type = "Both" # calc_add_risk() %>% # left_join(get_vax(), by = c("id", "date")) head(who_data)
We were running into issues where vaccination data were sometimes carried forward, but not always.
Since this is generally the behavior we want, I've applied it within SaviR using a new function, calc_vax_carryforward()
calc_vax_carryforward()
This function is used internally in get_vax()
and get_combined_table()
to carry-forward the following columns:
total_vaccinations
people_vaccinated
people_fully_vaccinated
total_boosters
total_vaccinations_per_hundred
people_vaccinated_per_hundred
people_fully_vaccinated_per_hundred
total_boosters_per_hundred
Passing columns to calc_vax_carryforward
overrides that behavior, but there isn't presently a need for that.
get_vax_dates()
Because vaccine data are carried-forward, the old way of computing the date the vaccine data were last updated
is no longer possible. Instead, I've created a function which computes those dates automatically, get_vax_dates()
get_vax_dates()
takes no arguments, but returns a data frame with 1 row per country detailing when each vaccine metric was last updated.
vax_dates <- get_vax_dates() head(vax_dates)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.