Learn R Programming

reactable (version 0.2.0)

colFormat: Column formatting options

Description

Column formatting options

Usage

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

Run this code
# NOT RUN {
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 = " \u00b0C")),
  percent = colDef(format = colFormat(percent = TRUE, digits = 1)),
  date = colDef(format = colFormat(date = TRUE, locale = "en-GB"))
))

# }

Run the code above in your browser using DataLab