View source: R/format_vector.R
| format_vector | R Documentation |
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
)
x |
A vector to be formatted. |
output |
Output format. One of "html", "latex", "typst", "markdown", etc. |
digits |
Number of significant digits or decimal places. |
num_fmt |
The format for numeric values; one of 'significant', 'significant_cell', 'decimal', or 'scientific'. |
num_zero |
Logical; if TRUE, trailing zeros are kept in "decimal" format (but not in "significant" format). |
num_suffix |
Logical; if TRUE display short numbers with |
num_mark_big |
Character to use as a thousands separator. |
num_mark_dec |
Decimal mark character. Default is the global option 'OutDec'. |
date |
A string passed to the |
bool |
A function to format logical columns. Defaults to title case. |
math |
Logical. If TRUE, wrap cell values in math mode |
other |
A function to format columns of other types. Defaults to |
replace |
Logical, String or Named list of vectors
|
escape |
Logical or "latex" or "html". If TRUE, escape special characters to display them as text in the format of the output of a
|
markdown |
Logical; if TRUE, render markdown syntax in cells. Ex: |
quarto |
Logical. Enable Quarto data processing and wrap cell content in a |
fn |
Function for custom formatting. Accepts a vector and returns a character vector of the same length. |
sprintf |
String passed to the |
linebreak |
NULL or a single string. If it is a string, replaces that string with appropriate line break sequences depending on the output format (HTML: |
This function formats a vector by passing it to format_tt(). All formatting arguments must be of length 1 or length(x).
A character vector with formatted values.
# 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"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.