colFormat: Column formatting options

Description Usage Arguments Value Examples

View source: R/columns.R

Description

Column formatting options

Usage

1
2
3
4
colFormat(prefix = NULL, suffix = NULL, digits = NULL,
  separators = FALSE, percent = FALSE, currency = NULL,
  datetime = FALSE, date = FALSE, time = FALSE, hour12 = NULL,
  locales = NULL)

Arguments

prefix

Prefix string.

suffix

Suffix string.

digits

Number of decimal digits to use for numbers.

separators

Whether to use grouping separators for numbers, such as thousands separators or thousand/lakh/crore separators. The format is locale-dependent.

percent

Format number as a percentage? The format is locale-dependent.

currency

Currency format. An ISO 4217 currency code such as "USD" for the US dollar, "EUR" for the euro, or "CNY" for the Chinese RMB. The format is locale-dependent.

datetime

Format as a locale-dependent date-time?

date

Format as a locale-dependent date?

time

Format as a locale-dependent time?

hour12

Whether to use 12-hour time (TRUE) or 24-hour time (FALSE). The default time convention is locale-dependent.

locales

Locales to use for number and date/time formatting. A character vector of BCP 47 language tags, such as "en-US" for English (United States), "hi" for Hindi, or "sv-SE" for Swedish (Sweden). Defaults to the locale of the browser.

Value

A column format object that can be used to customize data formatting in colDef().

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
data <- data.frame(
  price_USD = c(123456.56, 132, 5650.12),
  price_INR = c(350, 23208.552, 1773156.4),
  temp = c(22, NA, 31),
  percent = c(0.9525556, 0.5, 0.112),
  date = as.Date(c("2019-01-02", "2019-03-15", "2019-09-22"))
)

reactable(data, columns = list(
  price_USD = colDef(format = colFormat(prefix = "$", separators = TRUE, digits = 2)),
  price_INR = colDef(format = colFormat(currency = "INR", separators = TRUE, locale = "hi-IN")),
  temp = colDef(format = colFormat(suffix = " °C")),
  percent = colDef(format = colFormat(percent = TRUE, digits = 1)),
  date = colDef(format = colFormat(date = TRUE, locale = "en-GB"))
))

glin/reactable documentation built on Dec. 4, 2019, 11:47 p.m.