gt (version 0.8.0)

fmt_passthrough: Format by simply passing data through

Description

Format by passing data through no other transformation other than: (1) coercing to character (as all the fmt_*() functions do), and (2) applying text via the pattern argument (the default is to apply nothing). All of this is useful when don't want to modify the input data other than to decorate it within a pattern. Also, this function is useful when used as the formatter function in the summary_rows() function, where the output may be text or useful as is.

Usage

fmt_passthrough(
  data,
  columns,
  rows = everything(),
  escape = TRUE,
  pattern = "{x}"
)

Value

An object of class gt_tbl.

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(), and everything().

rows

Optional rows to format. Providing everything() (the default) results in all rows in columns being formatted. Alternatively, we can supply a vector of row captions within 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(), 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).

escape

An option to escape text according to the final output format of the table. For example, if a LaTeX table is to be generated then LaTeX escaping would be performed during rendering. By default this is set to TRUE and setting to FALSE would be useful in the case where text is crafted for a specific output format in mind.

pattern

A formatting pattern that allows for decoration of the formatted value. The value itself is represented by {x} and all other characters are taken to be string literals.

Targeting the values to be formatted

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. Keep only the char column. Pass the data in that column through but apply a simple pattern that adds an "s" to the non-NA values.

exibble %>%
  dplyr::select(char) %>%
  gt() %>%
  fmt_passthrough(
    columns = char,
    rows = !is.na(char),
    pattern = "{x}s"
  )

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

Function ID

3-16

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_percent(), fmt_roman(), fmt_scientific(), fmt_time(), fmt(), sub_large_vals(), sub_missing(), sub_small_vals(), sub_values(), sub_zero(), text_transform()