## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  out.width = "100%"
)

## -----------------------------------------------------------------------------
library(stats19)

## ----message=FALSE, warning=FALSE---------------------------------------------
# Read with readr (default)
col_readr = get_stats19(year = 2024, type = "collision", engine = "readr", silent = TRUE)

# Read with duckdb
col_duckdb = get_stats19(year = 2024, type = "collision", engine = "duckdb", silent = TRUE)

## -----------------------------------------------------------------------------
nrow(col_readr)
nrow(col_duckdb)

# Check fatal counts
sum(col_readr$collision_severity == "Fatal", na.rm = TRUE)
sum(col_duckdb$collision_severity == "Fatal", na.rm = TRUE)

## -----------------------------------------------------------------------------
if (requireNamespace("waldo", quietly = TRUE)) {
  waldo::compare(head(col_readr, 10), head(col_duckdb, 10))
}

## ----eval=FALSE---------------------------------------------------------------
# # This chunk is not evaluated because it requires downloading ~1.5GB of data
# # and can take several minutes to run with the readr engine.
# 
# # Download and read all collisions since 1979, but only keep those with speed_limit = 30
# crashes_30mph = get_stats19(year = 1979, type = "collision",
#                            engine = "duckdb",
#                            where = "speed_limit = 30")

