Let’s use the exibble dataset to create a simple, two-column gt table (keeping only the char and fctr columns). In the char column, we’ll transform the NA value to "elderberry" using the text_case_match() function. Over in the fctr column, some more sophisticated matches will be performed using text_case_match(). That column has spelled out numbers and we can produce these on the LHS with help from vec_fmt_spelled_num(). The replacements will contain descriptive text. In this last call of text_case_match(), 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
Next, let’s use a transformed version of the towny dataset 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.