The text_case_match() function

Use exibble to create a gt table. In the char column, transform the NA value to "elderberry". Over in the fctr column, perform some sophisticated matches on spelled-out numbers and replace with descriptive text. Here, we use a .default to replace text for any of those non-matched cases.

exibble |>
  dplyr::select(char, fctr) |>
  gt() |>
  text_case_match(
    NA ~ "elderberry",
    .locations = cells_body(columns = char)
  ) |>
  text_case_match(
    vec_fmt_spelled_num(1:4) ~ "one to four",
    vec_fmt_spelled_num(5:6) ~ "five or six",
    .default = "seven or more",
    .locations = cells_body(columns = fctr)
  )
char fctr
apricot one to four
banana one to four
coconut one to four
durian one to four
elderberry five or six
fig five or six
grapefruit seven or more
honeydew seven or more

Use towny to create a gt table. Transform the text in the csd_type column using two-sided formulas supplied to text_case_match(). We can replace matches on the LHS with Fontawesome icons furnished by the fontawesome R package.

towny |>
  dplyr::select(name, csd_type, population_2021) |>
  dplyr::filter(csd_type %in% c("city", "town")) |>
  dplyr::group_by(csd_type) |>
  dplyr::arrange(desc(population_2021)) |>
  dplyr::slice_head(n = 5) |>
  dplyr::ungroup() |>
  gt() |>
  fmt_integer() |>
  text_case_match(
    "city" ~ fontawesome::fa("city"),
    "town" ~ fontawesome::fa("house-chimney")
  ) |>
  cols_label(
    name = "City/Town",
    csd_type = "",
    population_2021 = "Population"
  )
City/Town Population
Toronto 2,794,356
Ottawa 1,017,449
Mississauga 717,961
Brampton 656,480
Hamilton 569,353
Oakville 213,759
Whitby 138,501
Milton 132,979
Ajax 126,666
Newmarket 87,942