The fmt_roman() function

Create a tibble of small numeric values and generate a gt table. Format the roman column to appear as Roman numerals with fmt_roman().

dplyr::tibble(arabic = c(1, 8, 24, 85), roman = arabic) |>
  gt(rowname_col = "arabic") |>
  fmt_roman(columns = roman)
roman
1 I
8 VIII
24 XXIV
85 LXXXV

Formatting values to Roman numerals can be very useful when combining such output with row labels (usually through cols_merge()). Here’s an example where we take a portion of the illness dataset and generate some row labels that combine (1) a row number (in lowercase Roman numerals), (2) the name of the test, and (3) the measurement units for the test (nicely formatted by way of fmt_units()):

illness |>
  dplyr::slice_head(n = 6) |>
  gt(rowname_col = "test") |>
  fmt_units(columns = units) |>
  cols_hide(columns = starts_with("day")) |>
  sub_missing(missing_text = "") |>
  cols_merge_range(col_begin = norm_l, col_end = norm_u) |>
  cols_add(i = 1:6) |>
  fmt_roman(columns = i, case = "lower", pattern = "{x}.") |>
  cols_merge(columns = c(test, i, units), pattern = "{2} {1} ({3})") |>
  cols_label(norm_l = "Normal Range") |>
  tab_stubhead(label = "Test")
Test Normal Range
i. Viral load (copies per mL)
ii. WBC (×109/L) 4–10.0
iii. Neutrophils (×109/L) 2–8.0
iv. RBC (×1012/L) 4–5.5
v. Hb (g/L) 120–160.0
vi. PLT (×109/L) 100–300.0