install.packages(c("tidyverse", "pointblank", "janitor"))ETC5521 Worksheet Week 3
Data validation with pointblank
🎯 Objectives
Practice setting up rule-based, automated data validation checks, using the pointblank package, applied to the World Development Indicators (WDI) data from the week 3 lecture. This should take about 30 minutes.
📦 Data
This is the same tidying used in lecture – you don’t need to change anything here, just run it to get wdi (long, one row per country/year/series) and wdi2016 (a single cross-section).
library(janitor)
raw_dat <- read_csv(here::here("data/world-development-indicators.csv"),
na = "..", n_max = 11935)
wdi <- raw_dat |>
select(`Country Code`, `Series Code`, `1969 [YR1969]`:`2018 [YR2018]`) |>
rename_all(make_clean_names) |>
pivot_longer(x1969_yr1969:x2018_yr2018,
names_to = "year",
values_to = "value") |>
mutate(year = as.numeric(str_sub(year, 2, 5))) |>
pivot_wider(names_from = series_code, values_from = value)
wdi2016 <- wdi |> filter(year == 2016)Three series we’ll use today:
SP.DYN.LE00.IN: life expectancy at birth, total (years)SP.POP.TOTL: population, totalEN.ATM.CO2E.PC: CO2 emissions (metric tons per capita) – note this series stops being reported after 2014, so it will be entirely missing inwdi2016.