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)

Background

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.

Standardization of geography columns across datasets

Black box warning

This will have a pretty substantial impact on all products, and will likely break most existing downstream code...

Motivation

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).

Impact

owid_testing_meta, get_owid_testing_meta()
get_testing() (and all inner functions)
get_covid_df()
get_vax(), get_vax_manufacturers()
onetable
head(get_covid_df("WHO"))
head(get_vax())

New "Starting Block" function 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)

Vaccine carry-forward

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:

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)


CDCgov/SaviR documentation built on April 14, 2025, 7:46 a.m.