Format a Vector
format_vector(
x,
output = "html",
digits = NULL,
num_fmt = "significant",
num_zero = FALSE,
num_suffix = FALSE,
num_mark_big = "",
num_mark_dec = getOption("OutDec", default = "."),
date = NULL,
bool = NULL,
math = FALSE,
other = NULL,
replace = FALSE,
escape = FALSE,
markdown = FALSE,
quarto = FALSE,
fn = NULL,
sprintf = NULL,
linebreak = NULL
)
A character vector with formatted values.
A vector to be formatted.
Output format. One of "html", "latex", "typst", "markdown", etc.
Number of significant digits or decimal places.
The format for numeric values; one of 'significant', 'significant_cell', 'decimal', or 'scientific'.
Logical; if TRUE, trailing zeros are kept in "decimal" format (but not in "significant" format).
Logical; if TRUE display short numbers with digits
significant digits and K (thousands), M (millions), B (billions), or T (trillions) suffixes.
Character to use as a thousands separator.
Decimal mark character. Default is the global option 'OutDec'.
A string passed to the format()
function, such as "%Y-%m-%d". See the "Details" section in ?strptime
A function to format logical columns. Defaults to title case.
Logical. If TRUE, wrap cell values in math mode $..$
. This is useful for LaTeX output or with HTML MathJax options(tinytable_html_mathjax=TRUE)
.
A function to format columns of other types. Defaults to as.character()
.
Logical, String or Named list of vectors
TRUE: Replace NA
and NaN
by an empty string.
FALSE: Print NA
and NaN
as strings.
String: Replace NA
and NaN
entries by the user-supplied string.
Named list: Replace matching elements of the vectors in the list by theirs names. Example:
list("-" = c(NA, NaN), "Tiny" = -Inf, "Massive" = Inf)
Logical or "latex" or "html". If TRUE, escape special characters to display them as text in the format of the output of a tt()
table.
If i
and j
are both NULL
, escape all cells, column names, caption, notes, and spanning labels created by group_tt()
.
Logical; if TRUE, render markdown syntax in cells. Ex: _italicized text_
is properly italicized in HTML and LaTeX.
Logical. Enable Quarto data processing and wrap cell content in a data-qmd
span (HTML) or \QuartoMarkdownBase64{}
macro (LaTeX). See warnings in the Global Options section below.
Function for custom formatting. Accepts a vector and returns a character vector of the same length.
String passed to the ?sprintf
function to format numbers or interpolate strings with a user-defined pattern (similar to the glue
package, but using Base R).
NULL or a single string. If it is a string, replaces that string with appropriate line break sequences depending on the output format (HTML: <br>
, LaTeX: \\\\
, Typst: \\
). Markdown output is excluded from line break replacement.
This function formats a vector by passing it to format_tt()
. All formatting arguments must be of length 1 or length(x)
.
# Format numeric vector
format_vector(c(1234.567, 9876.543), digits = 2, num_mark_big = ",")
# Format dates
dates <- as.Date(c("2023-01-01", "2023-12-31"))
format_vector(dates, date = "%B %d, %Y")
# Format logical values
format_vector(c(TRUE, FALSE, TRUE), bool = function(x) ifelse(x, "Yes", "No"))
Run the code above in your browser using DataLab