All formatting functions in gt are quite consistent. All functions that start
with the common fmt_*()
prefix have the following points in common
Details
Let's use the exibble data for this.
Examples
gt_tbl <- gt(exibble)
#
# They all have `columns` and `rows` to specify target cells and default to
# styling all compatible cells.
#
# By default, they apply styling to all compatible columns.
# Will style all numeric columns
gt_tbl %>% fmt_number()
num
char
fctr
date
time
datetime
currency
row
group
# will style the time column
gt_tbl %>% fmt_time(columns = time)
num
char
fctr
date
time
datetime
currency
row
group
# Will style nothing since is only compatible with logical values
gt_tbl %>% fmt_tf()
#> Warning: invalid factor level, NA generated
#> Warning: invalid factor level, NA generated
num
char
fctr
date
time
datetime
currency
row
group
#
# Their order has importance as the last styling will have priority.
#
# Will style all numeric columns as integer
# fmt_number() will have no effect
gt_tbl %>% fmt_number() %>% fmt_integer()
num
char
fctr
date
time
datetime
currency
row
group
#
# Therefore, to apply different styling, it is important to specify columns or rows.
#
# Will style all numeric columns as number and as currency the currency column.
# fmt_number() will have no effect
gt_tbl %>% fmt_number() %>% fmt_integer(currency)
num
char
fctr
date
time
datetime
currency
row
group