lt_format: Format numeric columns

View source: R/tab.R

lt_formatR Documentation

Format numeric columns

Description

Control the number of decimal places and thousands separator for numeric columns. Columns passed to this function are excluded from automatic formatting (see the auto_format argument of lt()). To disable auto-format for a column without otherwise changing its display, call lt_format(x, ~col) with no other arguments.

Usage

lt_format(
  x,
  columns,
  decimals = NULL,
  sig_digits = NULL,
  big_mark = NULL,
  percent = NULL,
  prefix = NULL,
  suffix = NULL
)

Arguments

x

An lt() object.

columns

Columns to select: a character vector of column names, integer positions, or a one-sided formula. A formula whose right-hand side references the pronoun . (the character vector of column names) is evaluated as a predicate, e.g. ~ endsWith(., "_time") selects all columns whose names end with ⁠_time⁠; otherwise the bare names on the right-hand side are used, e.g. ~ x + y.

decimals

Number of decimal places (default NULL means no change).

sig_digits

Number of significant digits (e.g., 3). Cannot be combined with decimals. Unlike decimals, which fixes the number of places after the decimal point, this targets the total number of meaningful digits, which is useful for columns spanning several orders of magnitude.

big_mark

Thousands separator (e.g., ","). NULL or "" means none.

percent

If TRUE, multiply values by 100 and append "%". If "%", only append "%" without multiplying (for values already in percent scale).

prefix

String prepended to each formatted value (e.g., "$").

suffix

String appended to each formatted value (e.g., " kg").

Value

x with the formatting recorded.

Examples

lt(head(mtcars)) |> lt_format(~ mpg + wt, decimals = 1, big_mark = ",")
d = data.frame(Item = c("A", "B"), Price = c(1234.5, 678.9))
lt(d) |> lt_format(~ Price, decimals = 2, big_mark = ",", prefix = "$")
lt(d) |> lt_format(~ Price, sig_digits = 3)

lt documentation built on Oct. 17, 2026, 9:06 a.m.