This function formats the columns of a data frame based on the column type (logical, date, numeric). It allows various formatting options like significant digits, decimal points, and scientific notation. It also includes custom formatting for date and boolean values. If this function is applied several times to the same cell, the last transformation is retained and the previous calls are ignored, except for the escape argument which can be applied to previously transformed data.
i: Row indices where the formatting should be applied.
j: Column indices where the styling should be applied. Can be:
Integer vectors indicating column positions.
Character vector indicating column names.
A single string specifying a Perl-style regular expression used to match column names.
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 digits significant digits and K (thousands), M (millions), B (billions), or T (trillions) suffixes.
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 format() function, such as "%Y-%m-%d". See the "Details" section in ?strptime
bool: A function to format logical columns. Defaults to title case.
math: Logical. If TRUE, wrap cell values in math mode $..$. This is useful for LaTeX output or with HTML MathJax options(tinytable_html_mathjax=TRUE).
other: A function to format columns of other types. Defaults to as.character().
replace: 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:
escape: 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().
markdown: Logical; if TRUE, render markdown syntax in cells. Ex: _italicized text_ is properly italicized in HTML and LaTeX.
quarto: 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.
fn: Function for custom formatting. Accepts a vector and returns a character vector of the same length.
sprintf: 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).
Returns
A data frame with formatted columns.
Global options
Options can be set with options() and change the default behavior of tinytable. For example:
options(tinytable_tt_digits = 4)
tt(head(iris))
You can set options in a script or via .Rprofile. Note: be cautious with .Rprofile settings as they may affect reproducibility.
Default values for function arguments
tt()
tinytable_tt_digits
tinytable_tt_caption
tinytable_tt_notes
tinytable_tt_width
tinytable_tt_theme
tinytable_tt_rownames
format_tt()
tinytable_format_digits
tinytable_format_num_fmt
tinytable_format_num_zero
tinytable_format_num_suffix
tinytable_format_num_mark_big
tinytable_format_num_mark_dec
tinytable_format_date
tinytable_format_bool
tinytable_format_other
tinytable_format_replace
tinytable_format_escape
tinytable_format_markdown
tinytable_format_quarto
tinytable_format_fn
tinytable_format_sprintf
save_tt()
tinytable_save_overwrite
theme_tt()
Placement:
tinytable_theme_placement_float
tinytable_theme_placement_horizontal
Resize:
tinytable_theme_resize_width
tinytable_theme_resize_direction
Multipage:
tinytable_theme_multipage_rowhead
tinytable_theme_multipage_rowfoot
Tabular:
tinytable_theme_tabular_style
print.tinytable()
tinytable_print_output
Output-specific options
HTML
tinytable_html_mathjax: Insert MathJax scripts (warning: may conflict if MathJax is loaded elsewhere)
tinytable_html_portable: Insert base64 encoded images directly in HTML for plot_tt()
PDF
tinytable_pdf_clean: Delete temporary and log files
tinytable_pdf_engine: Choose between "xelatex", "pdflatex", "lualatex"
Quarto
The format_tt(quarto=TRUE) argument enables Quarto data processing with some limitations:
The \QuartoMarkdownBase64{} LaTeX macro may not process references and markdown as expected
Quarto processing may conflict with tinytable styling/formatting
Options:
tinytable_quarto_disable_processing: Disable Quarto cell processing
tinytable_print_rstudio_notebook: Display tables "inline" or in "viewer" for RStudio notebooks
tinytable_quarto_figure: Control Typst figure environment in Quarto