Learn R Programming

gt (version 0.8.0)

fmt_roman: Format values as Roman numerals

Description

With numeric values in a gt table we can transform those to Roman numerals, rounding values as necessary.

Usage

fmt_roman(
  data,
  columns,
  rows = everything(),
  case = c("upper", "lower"),
  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).

case

Should Roman numerals should be rendered as uppercase ("upper") or lowercase ("lower") letters? By default, this is set to "upper".

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

Create a tibble of small numeric values and generate a gt table. Format the roman column to appear as Roman numerals with fmt_roman().

dplyr::tibble(arabic = c(1, 8, 24, 85), roman = arabic) %>%
  gt(rowname_col = "arabic") %>%
  fmt_roman(columns = roman)

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

Function ID

3-9

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