## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", warning = FALSE, message = FALSE)
library(mudnester)

## ----exact--------------------------------------------------------------------
set.seed(1)
df <- data.frame(age = c(0.2, 3, 14, 25, 50, 67, 80, 92))

preening(df, age_col = "age", scheme = "atagi_covid19_2025")$age_group

## ----filter-single------------------------------------------------------------
# vaccination + paediatric + max 3 bands → exactly one match
preening(df, age_col = "age", family = "vaccination",
         focus = "paediatric", max_bands = 3)$age_group

## ----list-schemes-------------------------------------------------------------
list_age_schemes(family = "surveillance")

## ----multi-match-error, error=TRUE--------------------------------------------
try({
# Multiple paediatric schemes exist — preening() asks you to choose
preening(df, age_col = "age", focus = "paediatric")
})

## ----focus-tags---------------------------------------------------------------
list_age_schemes(focus = "aged_care")

## ----focus-broad--------------------------------------------------------------
# Quick summary schemes for small datasets or executive reports
list_age_schemes(focus = "broad", max_bands = 5)

## ----neonatal-----------------------------------------------------------------
neonates <- data.frame(age_days = c(0, 0.5, 2, 5, 15, 30))
preening(neonates, age_col = "age_days", scheme = "neonatal_early",
         age_unit = "days")$age_group

## ----custom-------------------------------------------------------------------
preening(
  df,
  age_col    = "age",
  scheme     = "custom",
  age_breaks = c(0, 18, 40, 65, Inf),
  age_labels = c("0-17", "18-39", "40-64", "65+")
)$age_group

## ----catchall-----------------------------------------------------------------
# rsv_older_adult is scoped to 60+. A child record still gets a band.
data.frame(age = c(3, 65, 80)) |>
  preening(age_col = "age", scheme = "rsv_older_adult")

## ----roost-integration, eval=FALSE--------------------------------------------
# df |>
#   preening(age_col = "age", scheme = "flucan_sentinel") |>
#   roost(date_col = "onset_date", time_unit = "month",
#         group_cols = "age_group")

