Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

fmt_missing

Format missing values


Description

Wherever there is missing data (i.e., NA values) a customizable mark may present better than the standard NA text that would otherwise appear. The fmt_missing() function allows for this replacement through its missing_text argument (where an em dash serves as the default).

Usage

fmt_missing(data, columns, rows = NULL, 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 vars(), 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(), and everything().

rows

Optional rows to format. Not providing any value results in all rows in columns being formatted. Can either be a vector of row captions provided c(), 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(), and everything(). 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). A number of helper functions exist to make targeting more effective. Conditional formatting is possible by providing a conditional expression to the rows argument. See the Arguments section for more information on this.

Value

An object of class gt_tbl.

Figures

Function ID

3-10

See Also

Examples

# Use `exibble` to create a gt table;
# NA values in different columns will
# be given replacement text
tab_1 <-
  exibble %>%
  dplyr::select(-row, -group) %>%
  gt() %>%
  fmt_missing(
    columns = 1:2,
    missing_text = "missing"
  ) %>%
  fmt_missing(
    columns = 4:7,
    missing_text = "nothing"
  )

gt

Easily Create Presentation-Ready Display Tables

v0.2.2
MIT + file LICENSE
Authors
Richard Iannone [aut, cre] (<https://orcid.org/0000-0003-3925-190X>), Joe Cheng [aut], Barret Schloerke [aut] (<https://orcid.org/0000-0001-9986-114X>), RStudio [cph, fnd]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.