Wherever there is missing data (i.e., NA
values) customizable content may
present better than the standard NA
text that would otherwise appear. The
sub_missing()
function allows for this replacement through its
missing_text
argument (where an em dash serves as the default).
Usage
sub_missing(
data,
columns = everything(),
rows = everything(),
missing_text = "---"
)
Arguments
- data
A table object that is created using the
gt()
function.- columns
The columns to format. Can either be a series of column names provided in
c()
, a vector of column indices, or a helper function focused on selections. The select helper functions are:starts_with()
,ends_with()
,contains()
,matches()
,one_of()
,num_range()
, andeverything()
.- rows
Optional rows to format. Providing
everything()
(the default) results in all rows incolumns
being formatted. Alternatively, we can supply a vector of row captions withinc()
, a vector of row indices, or a helper function focused on selections. The select helper functions are:starts_with()
,ends_with()
,contains()
,matches()
,one_of()
,num_range()
, andeverything()
. We can also use expressions to filter down to the rows we need (e.g.,[colname_1] > 100 & [colname_2] < 50
).- missing_text
The text to be used in place of
NA
values in the rendered table.
Details
Targeting of values is done through columns
and additionally by rows
(if
nothing is provided for rows
then entire columns are selected). Conditional
formatting is possible by providing a conditional expression to the rows
argument. See the Arguments section for more information on this.
Examples
Use exibble
to create a gt table. The NA
values in different
columns will be given replacement text with two calls of sub_missing()
.
exibble %>%
dplyr::select(-row, -group) %>%
gt() %>%
sub_missing(
columns = 1:2,
missing_text = "missing"
) %>%
sub_missing(
columns = 4:7,
missing_text = "nothing"
)
See also
Other data formatting functions:
data_color()
,
fmt_bytes()
,
fmt_currency()
,
fmt_datetime()
,
fmt_date()
,
fmt_duration()
,
fmt_engineering()
,
fmt_fraction()
,
fmt_integer()
,
fmt_markdown()
,
fmt_number()
,
fmt_partsper()
,
fmt_passthrough()
,
fmt_percent()
,
fmt_roman()
,
fmt_scientific()
,
fmt_time()
,
fmt()
,
sub_large_vals()
,
sub_small_vals()
,
sub_values()
,
sub_zero()
,
text_transform()