Skip to contents

Wherever there is missing data (i.e., NA values) customizable content may present better than the standard NA text that would otherwise appear. sub_missing() 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

The gt table data object

obj:<gt_tbl> // required

This is the gt table object that is commonly created through use of the gt() function.

columns

Columns to target

<column-targeting expression> // default: everything()

The columns to which substitution operations are constrained. Can either be a series of column names provided in c(), a vector of column indices, or a select helper function (e.g. starts_with(), ends_with(), contains(), matches(), num_range(), and everything()).

rows

Rows to target

<row-targeting expression> // default: everything()

In conjunction with columns, we can specify which of their rows should form a constraint for targeting operations. The default everything() results in all rows in columns being formatted. Alternatively, we can supply a vector of row IDs within c(), a vector of row indices, or a select helper function (e.g. starts_with(), ends_with(), contains(), matches(), num_range(), 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

Replacement text for NA values

scalar<character> // default: "---"

The text to be used in place of NA values in the rendered table. We can optionally use md() or html() to style the text as Markdown or to retain HTML elements in the text.

Value

An object of class gt_tbl.

Examples

Use select columns from the exibble dataset to create a gt table. The NA values in different columns (here, we are using column indices in columns) will be given two variations of replacement text with two separate 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"
  )

This image of a table was generated from the first code example in the `sub_missing()` help file.

Function ID

3-31

Function Introduced

v0.6.0 (May 24, 2022)