| Title: | Simple and Configurable Tables in 'HTML', 'LaTeX', 'Markdown', 'Word', 'PNG', 'PDF', and 'Typst' Formats |
|---|---|
| Description: | Create highly customized tables with this simple and dependency-free package. Data frames can be converted to 'HTML', 'LaTeX', 'Markdown', 'Word', 'PNG', 'PDF', or 'Typst' tables. The user interface is minimalist and easy to learn. The syntax is concise. 'HTML' tables can be customized using the flexible 'Bootstrap' framework, and 'LaTeX' code with the 'tabularray' package. |
| Authors: | Vincent Arel-Bundock [aut, cre] (ORCID: <https://orcid.org/0000-0003-2042-7063>) |
| Maintainer: | Vincent Arel-Bundock <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.16.0.13 |
| Built: | 2026-06-01 05:06:09 UTC |
| Source: | https://github.com/vincentarelbundock/tinytable |
Create highly customized tables with this simple and dependency-free package. Data frames can be converted to 'HTML', 'LaTeX', 'Markdown', 'Word', 'PNG', 'PDF', or 'Typst' tables. The user interface is minimalist and easy to learn. The syntax is concise. 'HTML' tables can be customized using the flexible 'Bootstrap' framework, and 'LaTeX' code with the 'tabularray' package.
Index of help topics:
format_tt Format columns of a data frame
format_vector Format a Vector
group_tt Spanning labels to identify groups of rows or
columns
plot_tt Insert images and inline plots into tinytable
objects
plot_vector Create Plot Vector
print.tinytable Print, display, or convert a tinytable object
rbind2,tinytable,tinytable-method
Combine 'tinytable' objects by rows
(vertically)
save_tt Save a Tiny Table to File
style_tt Style a Tiny Table
style_vector Style a Vector with Text Formatting
subset.tinytable Subsetting a 'tinytable' object
theme_default Deprecated: Use theme_tinytable() instead
theme_empty Theme for a void table
theme_grid Grid theme with borders around all cells
theme_html HTML-specific styles and options
theme_latex LaTeX-Specific Theme for 'tinytable'
theme_markdown Markdown theme with optional ANSI color support
and grid customization
theme_revealjs RevealJS presentation theme
theme_rotate Rotate table or cell content
theme_striped Striped theme with alternating row colors
theme_tinytable Default theme for TinyTable
theme_tt Deprecated: Use format-specific theme functions
instead
theme_typst Typst-specific styles and options
tinytable-package Simple and Configurable Tables in 'HTML',
'LaTeX', 'Markdown', 'Word', 'PNG', 'PDF', and
'Typst' Formats
tt Draw a Tiny Table
Vincent Arel-Bundock <[email protected]>
Vincent Arel-Bundock [aut, cre] (ORCID: <https://orcid.org/0000-0003-2042-7063>)
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.
Each call to format_tt() is recorded and later replayed sequentially at render time, so later calls operate on the output of earlier ones.
Arguments are executed in a fixed order inside each call (see code below), so combining features such as linebreak, escape, markdown, etc. in a single call may produce surprising results.
Chain multiple calls when you need finer control (e.g., format_tt(escape = TRUE) |> format_tt(linebreak = "<br>")), keeping in mind that the second call will see the already-escaped text.
format_tt( x, i = NULL, j = NULL, digits = get_option("tinytable_format_digits", default = NULL), num_fmt = get_option("tinytable_format_num_fmt", default = "significant"), num_zero = get_option("tinytable_format_num_zero", default = FALSE), num_suffix = get_option("tinytable_format_num_suffix", default = FALSE), num_mark_big = get_option("tinytable_format_num_mark_big", default = ""), num_mark_dec = get_option("tinytable_format_num_mark_dec", default = getOption("OutDec", default = ".")), date = get_option("tinytable_format_date", default = NULL), bool = get_option("tinytable_format_bool", default = NULL), math = get_option("tinytable_format_math", default = FALSE), other = get_option("tinytable_format_other", default = NULL), replace = get_option("tinytable_format_replace", default = FALSE), escape = get_option("tinytable_format_escape", default = FALSE), markdown = get_option("tinytable_format_markdown", default = FALSE), quarto = get_option("tinytable_format_quarto", default = FALSE), fn = get_option("tinytable_format_fn", default = NULL), sprintf = get_option("tinytable_format_sprintf", default = NULL), linebreak = get_option("tinytable_format_linebreak", default = NULL), output = get_option("tinytable_format_output", default = NULL) ) tt_format( x, i = NULL, j = NULL, digits = get_option("tinytable_format_digits", default = NULL), num_fmt = get_option("tinytable_format_num_fmt", default = "significant"), num_zero = get_option("tinytable_format_num_zero", default = FALSE), num_suffix = get_option("tinytable_format_num_suffix", default = FALSE), num_mark_big = get_option("tinytable_format_num_mark_big", default = ""), num_mark_dec = get_option("tinytable_format_num_mark_dec", default = getOption("OutDec", default = ".")), date = get_option("tinytable_format_date", default = NULL), bool = get_option("tinytable_format_bool", default = NULL), math = get_option("tinytable_format_math", default = FALSE), other = get_option("tinytable_format_other", default = NULL), replace = get_option("tinytable_format_replace", default = FALSE), escape = get_option("tinytable_format_escape", default = FALSE), markdown = get_option("tinytable_format_markdown", default = FALSE), quarto = get_option("tinytable_format_quarto", default = FALSE), fn = get_option("tinytable_format_fn", default = NULL), sprintf = get_option("tinytable_format_sprintf", default = NULL), linebreak = get_option("tinytable_format_linebreak", default = NULL), output = get_option("tinytable_format_output", default = NULL) )format_tt( x, i = NULL, j = NULL, digits = get_option("tinytable_format_digits", default = NULL), num_fmt = get_option("tinytable_format_num_fmt", default = "significant"), num_zero = get_option("tinytable_format_num_zero", default = FALSE), num_suffix = get_option("tinytable_format_num_suffix", default = FALSE), num_mark_big = get_option("tinytable_format_num_mark_big", default = ""), num_mark_dec = get_option("tinytable_format_num_mark_dec", default = getOption("OutDec", default = ".")), date = get_option("tinytable_format_date", default = NULL), bool = get_option("tinytable_format_bool", default = NULL), math = get_option("tinytable_format_math", default = FALSE), other = get_option("tinytable_format_other", default = NULL), replace = get_option("tinytable_format_replace", default = FALSE), escape = get_option("tinytable_format_escape", default = FALSE), markdown = get_option("tinytable_format_markdown", default = FALSE), quarto = get_option("tinytable_format_quarto", default = FALSE), fn = get_option("tinytable_format_fn", default = NULL), sprintf = get_option("tinytable_format_sprintf", default = NULL), linebreak = get_option("tinytable_format_linebreak", default = NULL), output = get_option("tinytable_format_output", default = NULL) ) tt_format( x, i = NULL, j = NULL, digits = get_option("tinytable_format_digits", default = NULL), num_fmt = get_option("tinytable_format_num_fmt", default = "significant"), num_zero = get_option("tinytable_format_num_zero", default = FALSE), num_suffix = get_option("tinytable_format_num_suffix", default = FALSE), num_mark_big = get_option("tinytable_format_num_mark_big", default = ""), num_mark_dec = get_option("tinytable_format_num_mark_dec", default = getOption("OutDec", default = ".")), date = get_option("tinytable_format_date", default = NULL), bool = get_option("tinytable_format_bool", default = NULL), math = get_option("tinytable_format_math", default = FALSE), other = get_option("tinytable_format_other", default = NULL), replace = get_option("tinytable_format_replace", default = FALSE), escape = get_option("tinytable_format_escape", default = FALSE), markdown = get_option("tinytable_format_markdown", default = FALSE), quarto = get_option("tinytable_format_quarto", default = FALSE), fn = get_option("tinytable_format_fn", default = NULL), sprintf = get_option("tinytable_format_sprintf", default = NULL), linebreak = get_option("tinytable_format_linebreak", default = NULL), output = get_option("tinytable_format_output", default = NULL) )
x |
A data frame or a vector to be formatted. |
i |
Numeric vector or string.
|
j |
Column indices where the styling should be applied. Can be:
|
digits |
Number of significant digits or decimal places, depending on the
|
num_fmt |
The format for numeric values; one of 'significant', 'significant_cell', 'decimal', or 'scientific'. See the |
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: |
output |
Apply formatting only if the |
A data frame with formatted columns.
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.
Nearly all of the package's functions retrieve their default values from global options. This allows you to set defaults once and apply them to all tables without needing to specify them each time. For example, to fix the the digits argument of the tt() function globally, call:
options(tinytable_tt_digits = 4)
In addition, some more specific options are available to control the behavior of the package in specific contexts.
tinytable_html_mathjax: Insert MathJax scripts (warning: may conflict if MathJax is loaded elsewhere)
tinytable_pdf_clean: Delete temporary and log files for pdf output in save_tt()
tinytable_color_name_normalization: Enable/disable automatic color name processing (default: TRUE). When enabled, R color names recognized by col2rgb() are converted to hex format for consistent rendering across HTML, LaTeX, and Typst formats. If R color conversion fails, LaTeX color names are used as fallback. Colors explicitly supplied as hex values with "#" prefix are passed through unchanged. Set to FALSE to disable processing and pass color names unchanged.
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
Example of Quarto-specific code in cells:
x <- data.frame(Math = "x^2^", Citation = "@Lovelace1842")
fn <- function(z) sprintf("<span data-qmd='%s'></span>", z)
tt(x) |> format_tt(i = 1, fn = fn)
For more details on Quarto table processing: https://quarto.org/docs/authoring/tables.html#disabling-quarto-table-processing
dat <- data.frame( a = rnorm(3, mean = 10000), b = rnorm(3, 10000) ) tab <- tt(dat) format_tt(tab, digits = 2, num_mark_dec = ",", num_mark_big = " " ) k <- tt(data.frame(x = c(0.000123456789, 12.4356789))) format_tt(k, digits = 2, num_fmt = "significant_cell") dat <- data.frame( a = c("Burger", "Halloumi", "Tofu", "Beans"), b = c(1.43202, 201.399, 0.146188, 0.0031), c = c(98938272783457, 7288839482, 29111727, 93945) ) tt(dat) |> format_tt(j = "a", sprintf = "Food: %s") |> format_tt(j = 2, digits = 1, num_fmt = "decimal", num_zero = TRUE) |> format_tt(j = "c", digits = 2, num_suffix = TRUE) y <- tt(data.frame(x = c(123456789.678, 12435.6789))) format_tt(y, digits = 3, num_mark_big = " ") x <- tt(data.frame(Text = c("_italicized text_", "__bold text__"))) format_tt(x, markdown = TRUE) # Line breaks using linebreak argument d <- data.frame(Text = "First line<br>Second line") tt(d) |> format_tt(linebreak = "<br>") # Non-standard evaluation (NSE) dat <- data.frame( w = c(143002.2092, 201399.181, 100188.3883), x = c(1.43402, 201.399, 0.134588), y = as.Date(c(897, 232, 198), origin = "1970-01-01"), z = c(TRUE, TRUE, FALSE) ) tt(dat) |> format_tt(i = w > 150000, j = w, digits = 0, num_mark_big = ",") tab <- data.frame(a = c(NA, 1, 2), b = c(3, NA, 5)) tt(tab) |> format_tt(replace = "-") dat <- data.frame( "LaTeX" = c("Dollars $", "Percent %", "Underscore _"), "HTML" = c("<br>", "<sup>4</sup>", "<emph>blah</emph>") ) tt(dat) |> format_tt(escape = TRUE)dat <- data.frame( a = rnorm(3, mean = 10000), b = rnorm(3, 10000) ) tab <- tt(dat) format_tt(tab, digits = 2, num_mark_dec = ",", num_mark_big = " " ) k <- tt(data.frame(x = c(0.000123456789, 12.4356789))) format_tt(k, digits = 2, num_fmt = "significant_cell") dat <- data.frame( a = c("Burger", "Halloumi", "Tofu", "Beans"), b = c(1.43202, 201.399, 0.146188, 0.0031), c = c(98938272783457, 7288839482, 29111727, 93945) ) tt(dat) |> format_tt(j = "a", sprintf = "Food: %s") |> format_tt(j = 2, digits = 1, num_fmt = "decimal", num_zero = TRUE) |> format_tt(j = "c", digits = 2, num_suffix = TRUE) y <- tt(data.frame(x = c(123456789.678, 12435.6789))) format_tt(y, digits = 3, num_mark_big = " ") x <- tt(data.frame(Text = c("_italicized text_", "__bold text__"))) format_tt(x, markdown = TRUE) # Line breaks using linebreak argument d <- data.frame(Text = "First line<br>Second line") tt(d) |> format_tt(linebreak = "<br>") # Non-standard evaluation (NSE) dat <- data.frame( w = c(143002.2092, 201399.181, 100188.3883), x = c(1.43402, 201.399, 0.134588), y = as.Date(c(897, 232, 198), origin = "1970-01-01"), z = c(TRUE, TRUE, FALSE) ) tt(dat) |> format_tt(i = w > 150000, j = w, digits = 0, num_mark_big = ",") tab <- data.frame(a = c(NA, 1, 2), b = c(3, NA, 5)) tt(tab) |> format_tt(replace = "-") dat <- data.frame( "LaTeX" = c("Dollars $", "Percent %", "Underscore _"), "HTML" = c("<br>", "<sup>4</sup>", "<emph>blah</emph>") ) tt(dat) |> format_tt(escape = TRUE)
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 )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, depending on the
|
num_fmt |
The format for numeric values; one of 'significant', 'significant_cell', 'decimal', or 'scientific'. See the |
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"))# 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"))
Spanning labels to identify groups of rows or columns
Alias for group_tt()
group_tt( x, i = getOption("tinytable_group_i", default = NULL), j = getOption("tinytable_group_j", default = NULL), ... ) tt_group( x, i = getOption("tinytable_group_i", default = NULL), j = getOption("tinytable_group_j", default = NULL), ... )group_tt( x, i = getOption("tinytable_group_i", default = NULL), j = getOption("tinytable_group_j", default = NULL), ... ) tt_group( x, i = getOption("tinytable_group_i", default = NULL), j = getOption("tinytable_group_j", default = NULL), ... )
x |
A data frame, data table, or tibble to be rendered as a table. |
i |
Character vector, named list, or integer vector
|
j |
String, named list, or character matrix
|
... |
Other arguments are ignored. |
Warning: The style_tt() can normally be used to style the group headers, as expected, but that feature is not available for Markdown and Word tables.
An object of class tt representing the table.
Markdown is a text-only format that only supports these styles: italic, bold, strikeout. The width argument is also unavailable.
These limitations exist because there is no standard markdown syntax for the other styling options.
However, in terminals (consoles) that support it, tinytable can display colors and text styles using
ANSI escape codes by setting theme_markdown(ansi = TRUE). This allows for rich formatting in
compatible terminal environments.
Word tables only support these styles: italic, bold, strikeout. The width argument is also unavailable.
Moreover, the style_tt() function cannot be used to style headers inserted by the group_tt() function;
instead, you should style the headers directly in the header definition using markdown syntax:
group_tt(i = list("*italic header*" = 2)). These limitations are due to the fact that we create
Word documents by converting a markdown table to .docx via the Pandoc software, which requires
going through a text-only intermediate format.
# vector of row labels dat <- data.frame( label = c("a", "a", "a", "b", "b", "c", "a", "a"), x1 = rnorm(8), x2 = rnorm(8) ) tt(dat[, 2:3]) |> group_tt(i = dat$label) # named lists of labels tt(mtcars[1:10, 1:5]) |> group_tt( i = list( "Hello" = 3, "World" = 8 ), j = list( "Foo" = 2:3, "Bar" = 4:5 ) ) dat <- mtcars[1:9, 1:8] tt(dat) |> group_tt(i = list( "I like (fake) hamburgers" = 3, "She prefers halloumi" = 4, "They love tofu" = 7 )) tt(dat) |> group_tt( j = list( "Hamburgers" = 1:3, "Halloumi" = 4:5, "Tofu" = 7 ) ) x <- mtcars[1:5, 1:6] tt(x) |> group_tt(j = list("Hello" = 1:2, "World" = 3:4, "Hello" = 5:6)) |> group_tt(j = list("Foo" = 1:3, "Bar" = 4:6)) # column names with delimiters dat <- data.frame( A_id = 1, A_a1 = 2, A_a2 = "3", B_b1 = 4, B_b2 = 5, B_C = 6 ) tt(dat) |> group_tt(j = "_") # matrix insertion rowmat <- matrix(colnames(iris)) tt(head(iris, 7)) |> group_tt(i = c(2, 5), j = rowmat) rowmat <- matrix(c( "a", "b", "c", "d", "e", 1, 2, 3, 4, 5)) tt(head(iris, 7)) |> group_tt(i = 2, j = rowmat) |> style_tt(i = "groupi", background = "pink")# vector of row labels dat <- data.frame( label = c("a", "a", "a", "b", "b", "c", "a", "a"), x1 = rnorm(8), x2 = rnorm(8) ) tt(dat[, 2:3]) |> group_tt(i = dat$label) # named lists of labels tt(mtcars[1:10, 1:5]) |> group_tt( i = list( "Hello" = 3, "World" = 8 ), j = list( "Foo" = 2:3, "Bar" = 4:5 ) ) dat <- mtcars[1:9, 1:8] tt(dat) |> group_tt(i = list( "I like (fake) hamburgers" = 3, "She prefers halloumi" = 4, "They love tofu" = 7 )) tt(dat) |> group_tt( j = list( "Hamburgers" = 1:3, "Halloumi" = 4:5, "Tofu" = 7 ) ) x <- mtcars[1:5, 1:6] tt(x) |> group_tt(j = list("Hello" = 1:2, "World" = 3:4, "Hello" = 5:6)) |> group_tt(j = list("Foo" = 1:3, "Bar" = 4:6)) # column names with delimiters dat <- data.frame( A_id = 1, A_a1 = 2, A_a2 = "3", B_b1 = 4, B_b2 = 5, B_C = 6 ) tt(dat) |> group_tt(j = "_") # matrix insertion rowmat <- matrix(colnames(iris)) tt(head(iris, 7)) |> group_tt(i = c(2, 5), j = rowmat) rowmat <- matrix(c( "a", "b", "c", "d", "e", 1, 2, 3, 4, 5)) tt(head(iris, 7)) |> group_tt(i = 2, j = rowmat) |> style_tt(i = "groupi", background = "pink")
The plot_tt() function allows for the insertion of images and inline plots into
tinytable objects. This function can handle both local and web-based images.
plot_tt( x, i = NULL, j = NULL, fun = NULL, data = NULL, color = "black", xlim = NULL, height = 1, height_plot = 400, width_plot = 1200, images = NULL, sprintf = "%s", assets = "tinytable_assets", output = NULL, ... ) tt_plot( x, i = NULL, j = NULL, fun = NULL, data = NULL, color = "black", xlim = NULL, height = 1, height_plot = 400, width_plot = 1200, images = NULL, sprintf = "%s", assets = "tinytable_assets", output = NULL, ... )plot_tt( x, i = NULL, j = NULL, fun = NULL, data = NULL, color = "black", xlim = NULL, height = 1, height_plot = 400, width_plot = 1200, images = NULL, sprintf = "%s", assets = "tinytable_assets", output = NULL, ... ) tt_plot( x, i = NULL, j = NULL, fun = NULL, data = NULL, color = "black", xlim = NULL, height = 1, height_plot = 400, width_plot = 1200, images = NULL, sprintf = "%s", assets = "tinytable_assets", output = NULL, ... )
x |
A tinytable object. |
i |
Integer vector, the row indices where images are to be inserted. If |
j |
Integer vector, the column indices where images are to be inserted. If |
fun |
String or function to generate inline plots.
|
data |
a list of data frames or vectors to be used by the plotting functions in |
color |
string Name of color to use for inline plots (passed to the |
xlim |
Numeric vector of length 2. Controls the range of bar plots. |
height |
Numeric, the height of the images in the table in em units. |
height_plot |
Numeric, the height of generated plot images in pixels (default: 400). |
width_plot |
Numeric, the width of generated plot images in pixels (default: 1200). |
images |
Character vector, the paths to the images to be inserted. Paths are relative to the main table file or Quarto (Rmarkdown) document. |
sprintf |
Character string, a sprintf format string to format the generated cell content. Default is "%s" which displays the content as-is. Use this to wrap images or plots in custom markup. |
assets |
Path to the directory where generated assets are stored. This path is relative to the location where a table is saved. |
output |
Apply plot insertion only when the table is rendered in the specified format. A character vector of one or more of "latex", "html", "typst", or "markdown". If |
... |
Extra arguments are passed to the function in |
The plot_tt() can insert images and inline plots into tables.
A modified tinytable object with images or plots inserted.
## Not run: # Bar plots with single and dual colors dat <- data.frame( Metric = c("Sales", "Conversion", "Growth", "Efficiency"), Value = c(75, 45, 92, 38), Percentage = c(0.75, 0.45, 0.92, 0.38) ) tt(dat) |> plot_tt(j = 2, fun = "bar", data = as.list(dat$Value), color = "darkorange") |> plot_tt(j = 3, fun = "bar", data = as.list(dat$Percentage), color = c("steelblue", "lightgrey"), xlim = c(0, 1)) # Built-in plot types plot_data <- list(mtcars$mpg, mtcars$hp, mtcars$qsec) dat <- data.frame( Variables = c("mpg", "hp", "qsec"), Histogram = "", Density = "", Line = "" ) # Random data for sparklines lines <- lapply(1:3, \(x) data.frame(x = 1:10, y = rnorm(10))) tt(dat) |> plot_tt(j = 2, fun = "histogram", data = plot_data) |> plot_tt(j = 3, fun = "density", data = plot_data, color = "darkgreen") |> plot_tt(j = 4, fun = "line", data = lines, color = "blue") |> style_tt(j = 2:4, align = "c") # Custom function example (must have ... argument) custom_hist <- function(d, ...) { function() hist(d, axes = FALSE, ann = FALSE, col = "lightblue") } tt(data.frame(Variables = "mpg", Histogram = "")) |> plot_tt(j = 2, fun = custom_hist, data = list(mtcars$mpg)) ## End(Not run)## Not run: # Bar plots with single and dual colors dat <- data.frame( Metric = c("Sales", "Conversion", "Growth", "Efficiency"), Value = c(75, 45, 92, 38), Percentage = c(0.75, 0.45, 0.92, 0.38) ) tt(dat) |> plot_tt(j = 2, fun = "bar", data = as.list(dat$Value), color = "darkorange") |> plot_tt(j = 3, fun = "bar", data = as.list(dat$Percentage), color = c("steelblue", "lightgrey"), xlim = c(0, 1)) # Built-in plot types plot_data <- list(mtcars$mpg, mtcars$hp, mtcars$qsec) dat <- data.frame( Variables = c("mpg", "hp", "qsec"), Histogram = "", Density = "", Line = "" ) # Random data for sparklines lines <- lapply(1:3, \(x) data.frame(x = 1:10, y = rnorm(10))) tt(dat) |> plot_tt(j = 2, fun = "histogram", data = plot_data) |> plot_tt(j = 3, fun = "density", data = plot_data, color = "darkgreen") |> plot_tt(j = 4, fun = "line", data = lines, color = "blue") |> style_tt(j = 2:4, align = "c") # Custom function example (must have ... argument) custom_hist <- function(d, ...) { function() hist(d, axes = FALSE, ann = FALSE, col = "lightblue") } tt(data.frame(Variables = "mpg", Histogram = "")) |> plot_tt(j = 2, fun = custom_hist, data = list(mtcars$mpg)) ## End(Not run)
Create Plot Vector
plot_vector( output = "html", fun = NULL, data = NULL, color = "black", xlim = NULL, height = 1, height_plot = 400, width_plot = 1200, images = NULL, sprintf = "%s", assets = "tinytable_assets", ... )plot_vector( output = "html", fun = NULL, data = NULL, color = "black", xlim = NULL, height = 1, height_plot = 400, width_plot = 1200, images = NULL, sprintf = "%s", assets = "tinytable_assets", ... )
output |
Output format. One of "html", "latex", "typst", "markdown", etc. |
fun |
String or function to generate inline plots.
|
data |
a list of data frames or vectors to be used by the plotting functions in |
color |
string Name of color to use for inline plots (passed to the |
xlim |
Numeric vector of length 2. Controls the range of bar plots. |
height |
Numeric, the height of the images in the table in em units. |
height_plot |
Numeric, the height of generated plot images in pixels (default: 400). |
width_plot |
Numeric, the width of generated plot images in pixels (default: 1200). |
images |
Character vector, the paths to the images to be inserted. Paths are relative to the main table file or Quarto (Rmarkdown) document. |
sprintf |
Character string, a sprintf format string to format the generated cell content. Default is "%s" which displays the content as-is. Use this to wrap images or plots in custom markup. |
assets |
Path to the directory where generated assets are stored. This path is relative to the location where a table is saved. |
... |
Extra arguments are passed to the function in |
This function creates plots by creating a temporary tt() object and applying plot_tt(). It returns a character vector containing the image paths or HTML tags for the plots.
A character vector with plot file paths or HTML tags.
## Not run: # Create histogram plots plot_data <- list(rnorm(100), rnorm(50)) plot_vector(fun = "histogram", data = plot_data, output = "html") # Create density plots plot_vector(fun = "density", data = plot_data, output = "latex") # Create bar plots from single values bar_data <- list(0.5, 0.8, 0.3) plot_vector(fun = "barpct", data = bar_data, output = "html") ## End(Not run)## Not run: # Create histogram plots plot_data <- list(rnorm(100), rnorm(50)) plot_vector(fun = "histogram", data = plot_data, output = "html") # Create density plots plot_vector(fun = "density", data = plot_data, output = "latex") # Create bar plots from single values bar_data <- list(0.5, 0.8, 0.3) plot_vector(fun = "barpct", data = bar_data, output = "html") ## End(Not run)
This function is called automatically by R whenever a tinytable object is anprinted to the console or in an HTML viewer pane.
## S3 method for class 'tinytable' print(x, output = get_option("tinytable_print_output", default = NULL), ...)## S3 method for class 'tinytable' print(x, output = get_option("tinytable_print_output", default = NULL), ...)
x |
A data frame, data table, or tibble to be rendered as a table. |
output |
Format in which a Tiny Table is printed. One of:
When
|
... |
Other arguments are ignored. |
When printing to HTML in interactive() mode, a temporary file is created and viewer() is called to preview the file with the local browser (ex: Firefox or Chrome). The temporary file is then automatically cleaned up. On some operating systems, like some Linux distributions, browser do not have read access to the /tmp/ directory. In such cases, users can specify a custom location to store temporary HTML files. Note that this prevents tinytable from automatically cleaning up temporary files automatically.
options(tinytable_tempdir = "/home/username/temp_directory")
launch a browser window or cat() the table to console.
tinytable objects by rows (vertically)Combine tinytable objects by rows (vertically)
## S4 method for signature 'tinytable,tinytable' rbind2(x, y, use_names = TRUE, headers = TRUE, ...)## S4 method for signature 'tinytable,tinytable' rbind2(x, y, use_names = TRUE, headers = TRUE, ...)
x |
|
y |
|
use_names |
‘TRUE’ binds by matching column name, ‘FALSE’ by position |
headers |
Logical. TRUE inserts the colnames of |
... |
Additional arguments are ignored. |
Transformations recorded via format_tt() and style_tt() are evaluated at the very end of the rendering pipeline, after rbind2() has combined the tables. When headers are inserted or columns differ in type, the combined data is first coerced to character, so subsequent formatting/styling works on strings. Apply format_tt() directly to raw data frames before calling tt(), or re-run the formatting/styling steps on the combined table to preserve rounding and other rules.
Calls to other tinytable functions such as style_tt() or group_tt() are ignored when applied to x or y. These functions should be applied to the final table instead.
Information in these S4 slots is carried over from x to the combined table:
x@output
x@caption
x@width
Information in these S4 slots is concatenated and carried over to the combined table:
c(x@notes, y@notes)
This function relies on the rbindlist() function from the data.table package.
library(tinytable) x <- tt(mtcars[1:3, 1:2], caption = "Combine two tiny tables.") y <- tt(mtcars[4:5, 8:10]) # rbind() does not support additional aarguments # rbind2() supports additional arguments # basic combination rbind(x, y) rbind(x, y) |> format_tt(replace = "") # omit y header rbind2(x, y, headers = FALSE) # bind by position rather than column names rbind2(x, y, use_names = FALSE) # `iris` example with pre-tt() formatting dat <- iris[1:3, 1:4] a <- format_tt(dat, i = 1:3, digits = 1) |> tt() b <- format_tt(dat, i = 1:3, digits = 2) |> tt() rbind2(a, b)library(tinytable) x <- tt(mtcars[1:3, 1:2], caption = "Combine two tiny tables.") y <- tt(mtcars[4:5, 8:10]) # rbind() does not support additional aarguments # rbind2() supports additional arguments # basic combination rbind(x, y) rbind(x, y) |> format_tt(replace = "") # omit y header rbind2(x, y, headers = FALSE) # bind by position rather than column names rbind2(x, y, use_names = FALSE) # `iris` example with pre-tt() formatting dat <- iris[1:3, 1:4] a <- format_tt(dat, i = 1:3, digits = 1) |> tt() b <- format_tt(dat, i = 1:3, digits = 2) |> tt() rbind2(a, b)
This function saves an object of class tinytable to a specified file and format, with an option to overwrite existing files.
save_tt( x, output = get_option("tinytable_save_output", default = NULL), overwrite = get_option("tinytable_save_overwrite", default = FALSE) ) tt_save( x, output = get_option("tinytable_save_output", default = NULL), overwrite = get_option("tinytable_save_overwrite", default = FALSE) )save_tt( x, output = get_option("tinytable_save_output", default = NULL), overwrite = get_option("tinytable_save_overwrite", default = FALSE) ) tt_save( x, output = get_option("tinytable_save_output", default = NULL), overwrite = get_option("tinytable_save_overwrite", default = FALSE) )
x |
The tinytable object to be saved. |
output |
String or file path.
|
overwrite |
A logical value indicating whether to overwrite an existing file. |
A string with the table when output is a format, and the file path when output is a valid path.
.pdf output requires a full LaTeX installation on the local computer.
.png output requires the webshot2 package.
.html self-contained files and theme_typst(portable = TRUE) require the base64enc package.
tinytable uses the tabularray package from your LaTeX distribution to draw tables. tabularray, in turn, uses the special tblr, talltblr, and longtblr environments.
When rendering a document from Quarto or Rmarkdown directly to PDF, tinytable will populate the LaTeX preamble automatically with all the required packages. For standalone LaTeX documents, these commands should be inserted in the preamble manually:
Note: Your document will fail to compile to PDF in Quarto if you enable caching and you use tinytable due to missing LaTeX headers. To avoid this problem, set the option #| cache: false for the chunk(s) where you use tinytable.
\usepackage{tabularray}
\usepackage{float}
\usepackage{graphicx}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\UseTblrLibrary{siunitx}
\newcommand{\tinytableTabularrayUnderline}[1]{\underline{#1}}
\newcommand{\tinytableTabularrayStrikeout}[1]{\sout{#1}}
\NewTableCommand{\tinytableDefineColor}[3]{\definecolor{#1}{#2}{#3}}
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.
Nearly all of the package's functions retrieve their default values from global options. This allows you to set defaults once and apply them to all tables without needing to specify them each time. For example, to fix the the digits argument of the tt() function globally, call:
options(tinytable_tt_digits = 4)
In addition, some more specific options are available to control the behavior of the package in specific contexts.
tinytable_html_mathjax: Insert MathJax scripts (warning: may conflict if MathJax is loaded elsewhere)
tinytable_pdf_clean: Delete temporary and log files for pdf output in save_tt()
tinytable_color_name_normalization: Enable/disable automatic color name processing (default: TRUE). When enabled, R color names recognized by col2rgb() are converted to hex format for consistent rendering across HTML, LaTeX, and Typst formats. If R color conversion fails, LaTeX color names are used as fallback. Colors explicitly supplied as hex values with "#" prefix are passed through unchanged. Set to FALSE to disable processing and pass color names unchanged.
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
Example of Quarto-specific code in cells:
x <- data.frame(Math = "x^2^", Citation = "@Lovelace1842")
fn <- function(z) sprintf("<span data-qmd='%s'></span>", z)
tt(x) |> format_tt(i = 1, fn = fn)
For more details on Quarto table processing: https://quarto.org/docs/authoring/tables.html#disabling-quarto-table-processing
library(tinytable) x <- mtcars[1:4, 1:5] fn <- file.path(tempdir(), "test.html") tt(x) |> save_tt(fn, overwrite = TRUE) library(tinytable) filename <- file.path(tempdir(), "table.tex") tt(mtcars[1:4, 1:4]) |> save_tt(filename)library(tinytable) x <- mtcars[1:4, 1:5] fn <- file.path(tempdir(), "test.html") tt(x) |> save_tt(fn, overwrite = TRUE) library(tinytable) filename <- file.path(tempdir(), "table.tex") tt(mtcars[1:4, 1:4]) |> save_tt(filename)
Style a Tiny Table
Alias for style_tt()
style_tt( x, i = NULL, j = NULL, bold = NULL, italic = NULL, monospace = NULL, smallcap = NULL, underline = NULL, strikeout = NULL, color = NULL, background = NULL, fontsize = NULL, align = NULL, alignv = NULL, colspan = NULL, rowspan = NULL, indent = NULL, line = NULL, line_color = NULL, line_width = 0.1, line_trim = NULL, finalize = NULL, output = NULL, ... ) tt_style( x, i = NULL, j = NULL, bold = NULL, italic = NULL, monospace = NULL, smallcap = NULL, underline = NULL, strikeout = NULL, color = NULL, background = NULL, fontsize = NULL, align = NULL, alignv = NULL, colspan = NULL, rowspan = NULL, indent = NULL, line = NULL, line_color = NULL, line_width = 0.1, line_trim = NULL, finalize = NULL, output = NULL, ... )style_tt( x, i = NULL, j = NULL, bold = NULL, italic = NULL, monospace = NULL, smallcap = NULL, underline = NULL, strikeout = NULL, color = NULL, background = NULL, fontsize = NULL, align = NULL, alignv = NULL, colspan = NULL, rowspan = NULL, indent = NULL, line = NULL, line_color = NULL, line_width = 0.1, line_trim = NULL, finalize = NULL, output = NULL, ... ) tt_style( x, i = NULL, j = NULL, bold = NULL, italic = NULL, monospace = NULL, smallcap = NULL, underline = NULL, strikeout = NULL, color = NULL, background = NULL, fontsize = NULL, align = NULL, alignv = NULL, colspan = NULL, rowspan = NULL, indent = NULL, line = NULL, line_color = NULL, line_width = 0.1, line_trim = NULL, finalize = NULL, output = NULL, ... )
x |
A table object created by |
i |
Numeric vector, logical matrix, string, or unquoted expression.
|
j |
Column indices where the styling should be applied. Can be:
|
bold |
Logical; if |
italic |
Logical; if |
monospace |
Logical; if |
smallcap |
Logical; if |
underline |
Logical; if |
strikeout |
Logical; if |
color |
Text color. Colors are standardized across output formats and can be specified as:
|
background |
Background color. Same color specification options as the |
fontsize |
Font size in em units. Can be |
align |
A single character or a string with a number of characters equal to the number of columns in |
alignv |
A single character specifying vertical alignment. Valid characters include 't' (top), 'm' (middle), 'b' (bottom). |
colspan |
Number of columns a cell should span. |
rowspan |
Number of rows a cell should span. |
indent |
Text indentation in em units. Positive values only. |
line |
String determines if solid lines (rules or borders) should be drawn around the cell, row, or column.
|
line_color |
Color of the line. See the |
line_width |
Width of the line in em units (default: 0.1). |
line_trim |
String specifying line trimming. Acceptable values: "l" (left), "r" (right), "lr" (both sides). When specified, shortens the lines by 0.8pt on the specified side(s). Default: NULL (no trimming). |
finalize |
A function applied to the table object at the very end of table-building, for post-processing. For example, the function could use regular expressions to add LaTeX commands to the text version of the table hosted in |
output |
Apply styling only when the table is rendered in the specified format. A character vector of one or more of "latex", "html", "typst", or "markdown". If |
... |
extra arguments are ignored |
This function applies styling to a table created by tt(). It allows customization of text style (bold, italic, monospace), text and background colors, font size, cell width, text alignment, column span, and indentation. The function also supports passing native instructions to LaTeX (tabularray) and HTML (bootstrap) formats.
An object of class tt representing the table.
Markdown is a text-only format that only supports these styles: italic, bold, strikeout. The width argument is also unavailable.
These limitations exist because there is no standard markdown syntax for the other styling options.
However, in terminals (consoles) that support it, tinytable can display colors and text styles using
ANSI escape codes by setting theme_markdown(ansi = TRUE). This allows for rich formatting in
compatible terminal environments.
Word tables only support these styles: italic, bold, strikeout. The width argument is also unavailable.
Moreover, the style_tt() function cannot be used to style headers inserted by the group_tt() function;
instead, you should style the headers directly in the header definition using markdown syntax:
group_tt(i = list("*italic header*" = 2)). These limitations are due to the fact that we create
Word documents by converting a markdown table to .docx via the Pandoc software, which requires
going through a text-only intermediate format.
if (knitr::is_html_output()) options(tinytable_print_output = "html") library(tinytable) tt(mtcars[1:5, 1:6]) # Alignment tt(mtcars[1:5, 1:6]) |> style_tt(j = 1:5, align = "lcccr") # Colors and styles tt(mtcars[1:5, 1:6]) |> style_tt(i = 2:3, background = "black", color = "orange", bold = TRUE) # column selection with `j`` tt(mtcars[1:5, 1:6]) |> style_tt(j = 5:6, background = "pink") tt(mtcars[1:5, 1:6]) |> style_tt(j = "drat|wt", background = "pink") tt(mtcars[1:5, 1:6]) |> style_tt(j = c("drat", "wt"), background = "pink") tt(mtcars[1:5, 1:6], theme = "empty") |> style_tt( i = 2, j = 2, colspan = 3, rowspan = 2, align = "c", alignv = "m", color = "white", background = "black", bold = TRUE) tt(mtcars[1:5, 1:6], theme = "empty") |> style_tt( i = 0:3, j = 1:3, line = "tblr", line_width = 0.4, line_color = "teal") tt(mtcars[1:5, 1:6], theme = "striped") |> style_tt( i = c(2, 5), j = 3, strikeout = TRUE, fontsize = 0.7) # Non-standard evaluation (NSE) dat <- data.frame( w = c(143002.2092, 201399.181, 100188.3883), x = c(1.43402, 201.399, 0.134588), y = as.Date(c(897, 232, 198), origin = "1970-01-01"), z = c(TRUE, TRUE, FALSE) ) tt(dat) |> style_tt(i = w > 150000, j = c("w", "x"), color = "white", background = "black") tt(mtcars[1:5, 1:6]) |> theme_html(class = "table table-dark table-hover") inner <- " column{1-4}={halign=c}, hlines = {fg=white}, vlines = {fg=white}, cell{1,6}{odd} = {bg=teal7}, cell{1,6}{even} = {bg=green7}, cell{2,4}{1,4} = {bg=red7}, cell{3,5}{1,4} = {bg=purple7}, cell{2}{2} = {r=4,c=2}{bg=azure7}, " tt(mtcars[1:5, 1:4], theme = "empty") |> theme_latex(inner = inner) # Style group rows and non-group rows dat <- data.frame(x = 1:6, y = letters[1:6]) dat |> tt() |> group_tt(i = list("Group A" = 3)) |> style_tt(i = "groupi", background = "lightblue") |> style_tt(i = "~groupi", background = "lightgray") # unquote expressions dat <- mtcars[1:10,] dat <- dat[order(dat$am),] tt(dat) |> subset(mpg > 20) |> group_tt(am) # style elements: captions and colnames notes <- list( "*" = "Hello world", "a" = "Bacon ipsum dolor amet kevin t-bone porchetta.") tt(head(iris), width = .8, caption = "This is a Caption Example.", notes = notes) |> style_tt(2, 2, background = "pink", rowspan = 2, colspan = 2, alignv = "m", align = "c", line = "tblr") |> style_tt("colnames", italic = TRUE) |> style_tt("caption", smallcap = TRUE)if (knitr::is_html_output()) options(tinytable_print_output = "html") library(tinytable) tt(mtcars[1:5, 1:6]) # Alignment tt(mtcars[1:5, 1:6]) |> style_tt(j = 1:5, align = "lcccr") # Colors and styles tt(mtcars[1:5, 1:6]) |> style_tt(i = 2:3, background = "black", color = "orange", bold = TRUE) # column selection with `j`` tt(mtcars[1:5, 1:6]) |> style_tt(j = 5:6, background = "pink") tt(mtcars[1:5, 1:6]) |> style_tt(j = "drat|wt", background = "pink") tt(mtcars[1:5, 1:6]) |> style_tt(j = c("drat", "wt"), background = "pink") tt(mtcars[1:5, 1:6], theme = "empty") |> style_tt( i = 2, j = 2, colspan = 3, rowspan = 2, align = "c", alignv = "m", color = "white", background = "black", bold = TRUE) tt(mtcars[1:5, 1:6], theme = "empty") |> style_tt( i = 0:3, j = 1:3, line = "tblr", line_width = 0.4, line_color = "teal") tt(mtcars[1:5, 1:6], theme = "striped") |> style_tt( i = c(2, 5), j = 3, strikeout = TRUE, fontsize = 0.7) # Non-standard evaluation (NSE) dat <- data.frame( w = c(143002.2092, 201399.181, 100188.3883), x = c(1.43402, 201.399, 0.134588), y = as.Date(c(897, 232, 198), origin = "1970-01-01"), z = c(TRUE, TRUE, FALSE) ) tt(dat) |> style_tt(i = w > 150000, j = c("w", "x"), color = "white", background = "black") tt(mtcars[1:5, 1:6]) |> theme_html(class = "table table-dark table-hover") inner <- " column{1-4}={halign=c}, hlines = {fg=white}, vlines = {fg=white}, cell{1,6}{odd} = {bg=teal7}, cell{1,6}{even} = {bg=green7}, cell{2,4}{1,4} = {bg=red7}, cell{3,5}{1,4} = {bg=purple7}, cell{2}{2} = {r=4,c=2}{bg=azure7}, " tt(mtcars[1:5, 1:4], theme = "empty") |> theme_latex(inner = inner) # Style group rows and non-group rows dat <- data.frame(x = 1:6, y = letters[1:6]) dat |> tt() |> group_tt(i = list("Group A" = 3)) |> style_tt(i = "groupi", background = "lightblue") |> style_tt(i = "~groupi", background = "lightgray") # unquote expressions dat <- mtcars[1:10,] dat <- dat[order(dat$am),] tt(dat) |> subset(mpg > 20) |> group_tt(am) # style elements: captions and colnames notes <- list( "*" = "Hello world", "a" = "Bacon ipsum dolor amet kevin t-bone porchetta.") tt(head(iris), width = .8, caption = "This is a Caption Example.", notes = notes) |> style_tt(2, 2, background = "pink", rowspan = 2, colspan = 2, alignv = "m", align = "c", line = "tblr") |> style_tt("colnames", italic = TRUE) |> style_tt("caption", smallcap = TRUE)
Style a Vector with Text Formatting
style_vector( x, output = "html", bold = FALSE, italic = FALSE, monospace = FALSE, smallcap = FALSE, underline = FALSE, strikeout = FALSE, color = NULL, fontsize = NULL, indent = NULL )style_vector( x, output = "html", bold = FALSE, italic = FALSE, monospace = FALSE, smallcap = FALSE, underline = FALSE, strikeout = FALSE, color = NULL, fontsize = NULL, indent = NULL )
x |
A vector to be styled. |
output |
Output format for styling. One of "html", "latex", "typst", "markdown", "ansi". Defaults to "html". |
bold |
Logical; if |
italic |
Logical; if |
monospace |
Logical; if |
smallcap |
Logical; if |
underline |
Logical; if |
strikeout |
Logical; if |
color |
Text color. Must be of length 1 or
|
fontsize |
Font size in em units. Must be of length 1 or |
indent |
Text indentation in em units. Must be of length 1 or |
This function applies styling to a vector. It allows customization of text style (bold, italic, monospace), text color, font size, and text decorations (underline, strikeout). The styling is applied element-wise to the vector. Vectors are coerced with as.character() before styling.
A character vector with applied styling.
# Basic styling style_vector(c("Hello", "World"), bold = TRUE, color = "red") # Different styles per element style_vector( c("Bold text", "Italic text", "Monospace"), bold = c(TRUE, FALSE, FALSE), italic = c(FALSE, TRUE, FALSE), monospace = c(FALSE, FALSE, TRUE) ) # Single style applied to all elements style_vector(c("A", "B", "C"), color = "blue", fontsize = 1.2)# Basic styling style_vector(c("Hello", "World"), bold = TRUE, color = "red") # Different styles per element style_vector( c("Bold text", "Italic text", "Monospace"), bold = c(TRUE, FALSE, FALSE), italic = c(FALSE, TRUE, FALSE), monospace = c(FALSE, FALSE, TRUE) ) # Single style applied to all elements style_vector(c("A", "B", "C"), color = "blue", fontsize = 1.2)
tinytable objectReturn subsets tinytable which meet conditions.
## S3 method for class 'tinytable' subset(x, subset, select, drop = FALSE, ...)## S3 method for class 'tinytable' subset(x, subset, select, drop = FALSE, ...)
x |
object to be subsetted. |
subset |
logical expression indicating elements or rows to keep: missing values are taken as false. |
select |
expression, indicating columns to select from a data frame. |
drop |
passed on to |
... |
further arguments to be passed to or from other methods. |
theme_default() has been renamed to theme_tinytable(). This function is
deprecated and will be removed in a future version.
theme_default(x, ...)theme_default(x, ...)
x |
A tinytable object. |
... |
Additional arguments are ignored. |
A modified tinytable object.
This function calls styles and formatting applied to a tinytable object up to that point in the pipeline.
theme_empty(x, ...)theme_empty(x, ...)
x |
A tinytable object. |
... |
Additional arguments are ignored. |
Grid theme with borders around all cells
theme_grid(x, ...)theme_grid(x, ...)
x |
A |
... |
Additional arguments (ignored). |
A modified tinytable object.
HTML-specific styles and options
theme_html( x, engine = get_option("tinytable_html_engine", default = NULL), i = NULL, j = NULL, class = get_option("tinytable_html_class", default = NULL), css = get_option("tinytable_html_css", default = NULL), css_rule = get_option("tinytable_html_css_rule", default = NULL), script = get_option("tinytable_html_script", default = NULL), portable = get_option("tinytable_html_portable"), tabulator_columns = get_option("tinytable_html_tabulator_columns"), tabulator_css_rule = get_option("tinytable_html_tabulator_css_rule"), tabulator_layout = get_option("tinytable_html_tabulator_layout", default = "fitDataTable"), tabulator_options = get_option("tinytable_html_tabulator_options"), tabulator_pagination = get_option("tinytable_html_tabulator_pagination"), tabulator_search = get_option("tinytable_html_tabulator_search"), tabulator_stylesheet = get_option("tinytable_html_tabulator_stylesheet"), ... )theme_html( x, engine = get_option("tinytable_html_engine", default = NULL), i = NULL, j = NULL, class = get_option("tinytable_html_class", default = NULL), css = get_option("tinytable_html_css", default = NULL), css_rule = get_option("tinytable_html_css_rule", default = NULL), script = get_option("tinytable_html_script", default = NULL), portable = get_option("tinytable_html_portable"), tabulator_columns = get_option("tinytable_html_tabulator_columns"), tabulator_css_rule = get_option("tinytable_html_tabulator_css_rule"), tabulator_layout = get_option("tinytable_html_tabulator_layout", default = "fitDataTable"), tabulator_options = get_option("tinytable_html_tabulator_options"), tabulator_pagination = get_option("tinytable_html_tabulator_pagination"), tabulator_search = get_option("tinytable_html_tabulator_search"), tabulator_stylesheet = get_option("tinytable_html_tabulator_stylesheet"), ... )
x |
A |
engine |
Character string specifying the HTML engine: "tinytable", "bootstrap", or "tabulator". |
i |
Row indices. |
j |
Column indices. |
class |
String. HTML table class. |
css |
Character vector. CSS style declarations. |
css_rule |
String. CSS rules to customize table styling. Can be one of:
|
script |
String. Custom JavaScript code or script tags to inject into the HTML output. Useful for loading external JavaScript libraries like Plotly, D3, etc. |
portable |
Logical. Sets whether to create portable HTML output with embedded Javascript, CSS, and base64-encoded images. |
tabulator_columns |
Custom column definitions. |
tabulator_css_rule |
Complete CSS rules. |
tabulator_layout |
Character string. Table layout algorithm for column sizing. Default is "fitDataTable". Available options: "fitDataTable", "fitData", "fitDataFill", "fitDataStretch", "fitColumns". |
tabulator_options |
Custom Tabulator.js configuration options. |
tabulator_pagination |
Logical or numeric vector. Pagination settings for large tables.
|
tabulator_search |
Character or NULL. Search functionality position.
|
tabulator_stylesheet |
Character string. CSS stylesheet theme for Tabulator.js tables. Default is "bootstrap5". Available options: "default", "simple", "midnight", "modern", "site", "site_dark", "bootstrap3", "bootstrap4", "bootstrap5", "semanticui", "bulma", "materialize", or a custom HTTP URL starting with "http". |
... |
Additional arguments are ignored. |
## Not run: # Load an external JavaScript library library(tinytable) x <- tt(mtcars[1:5, 1:5]) x <- theme_html(x, script = '<script src="https://cdn.plot.ly/plotly-2.27.0.min.js"></script>') # Add custom inline JavaScript x <- tt(mtcars[1:5, 1:5]) x <- theme_html(x, script = '<script>console.log("Table loaded");</script>') ## End(Not run)## Not run: # Load an external JavaScript library library(tinytable) x <- tt(mtcars[1:5, 1:5]) x <- theme_html(x, script = '<script src="https://cdn.plot.ly/plotly-2.27.0.min.js"></script>') # Add custom inline JavaScript x <- tt(mtcars[1:5, 1:5]) x <- theme_html(x, script = '<script>console.log("Table loaded");</script>') ## End(Not run)
tinytable
This function provides comprehensive LaTeX-specific theming and configuration options
for tinytable objects. It allows customization of LaTeX environments, table layout,
multipage behavior, resizing, and placement within LaTeX documents.
theme_latex( x, inner = NULL, outer = NULL, environment = get_option("tinytable_latex_environment", default = NULL), environment_table = get_option("tinytable_latex_environment_table", default = TRUE), multipage = get_option("tinytable_latex_multipage", default = FALSE), rowhead = get_option("tinytable_latex_rowhead", 0L), rowfoot = get_option("tinytable_latex_rowfoot", 0L), resize_width = get_option("tinytable_latex_resize_width", 1), resize_height = get_option("tinytable_latex_resize_height", default = NULL), resize_direction = get_option("tinytable_latex_resize_direction", default = NULL), placement = get_option("tinytable_latex_placement", NULL), preamble = NULL, engine = NULL, ... )theme_latex( x, inner = NULL, outer = NULL, environment = get_option("tinytable_latex_environment", default = NULL), environment_table = get_option("tinytable_latex_environment_table", default = TRUE), multipage = get_option("tinytable_latex_multipage", default = FALSE), rowhead = get_option("tinytable_latex_rowhead", 0L), rowfoot = get_option("tinytable_latex_rowfoot", 0L), resize_width = get_option("tinytable_latex_resize_width", 1), resize_height = get_option("tinytable_latex_resize_height", default = NULL), resize_direction = get_option("tinytable_latex_resize_direction", default = NULL), placement = get_option("tinytable_latex_placement", NULL), preamble = NULL, engine = NULL, ... )
x |
A |
inner |
Character string specifying inner tabularray options. These options
control the internal formatting of the table (e.g., column alignment, spacing).
Will be added to any existing inner options. Default is |
outer |
Character string specifying outer tabularray options. These options
control the external formatting around the table. Will be added to any existing
outer options. Default is |
environment |
Character string specifying the LaTeX table environment to use. Options are:
Default is controlled by |
environment_table |
Logical indicating whether to wrap the table in a |
multipage |
Logical indicating whether to enable multipage table functionality.
When |
rowhead |
Integer specifying the number of header rows to repeat on each page
in multipage tables. Only valid with |
rowfoot |
Integer specifying the number of footer rows to repeat on each page
in multipage tables. Only valid with |
resize_width |
Numeric value between 0.01 and 1.0 specifying the target width
as a fraction of |
resize_height |
Numeric value between 0.01 and 1.0 specifying the target height
as a fraction of |
resize_direction |
Character string specifying how to resize tables that are too wide or too narrow. Options are:
Default is controlled by |
placement |
Character string specifying LaTeX float placement options for the
table environment (e.g., "h", "t", "b", "p", "H"). Only used when |
preamble |
Logical value specifying whether to include LaTeX preamble packages. If not NULL, overrides the table's preamble setting. |
engine |
Character string specifying the LaTeX engine to use for PDF compilation. Options are "xelatex", "pdflatex", or "lualatex". If not NULL, overrides the table's engine setting. |
... |
Additional arguments (currently unused). |
The function provides fine-grained control over LaTeX table output through several mechanisms:
Environment Selection: Different LaTeX environments offer different capabilities:
tblr: Modern tabularray syntax with full styling support
talltblr: Like tblr but optimized for tall tables
longtblr: Supports page breaks and repeated headers/footers
tabular: Basic LaTeX syntax, limited styling but maximum compatibility
Multipage Tables:
When multipage = TRUE or when rowhead/rowfoot are specified, the function
automatically switches to longtblr environment and disables the table wrapper.
This allows tables to break across pages while maintaining headers and footers.
Resizing:
The resize functionality uses LaTeX's \\resizebox command to automatically
adjust table dimensions based on content and page constraints. Use resize_width
to control width (fraction of \\linewidth) or resize_height to control height
(fraction of \\textheight). When resize_height is specified, the table is scaled
to fit the target height with width adjusting proportionally.
Tabularray Options: Inner and outer options directly control tabularray formatting. Inner options affect cell content and spacing, while outer options control the table's relationship with surrounding text.
A modified tinytable object with LaTeX-specific theming applied.
Markdown theme with optional ANSI color support and grid customization
theme_markdown( x, ansi = FALSE, style = NULL, vline = NULL, hline = NULL, hline_header = NULL, ... )theme_markdown( x, ansi = FALSE, style = NULL, vline = NULL, hline = NULL, hline_header = NULL, ... )
x |
A |
ansi |
Logical. If TRUE, enables ANSI color codes for grid styling. Default is FALSE. |
style |
Character. Markdown style format. Can be "grid" or "gfm". Default is NULL. |
vline |
Logical. Enable/disable vertical lines. Default is TRUE. |
hline |
Logical. Enable/disable horizontal lines. Default is TRUE. |
hline_header |
Logical. Enable/disable the special header separator line below column names. Default is TRUE. |
... |
Additional arguments (ignored). |
When ansi = TRUE, colors and text styling (bold, italic, strikeout, underline)
are applied using ANSI escape sequences for terminal display. ANSI colors require
a terminal or application that supports ANSI escape sequences. Common supported
terminals include: Terminal.app (macOS), iTerm2 (macOS), Windows Terminal, most
Linux terminals, RStudio Console, and VS Code terminal. Colors may not display
correctly in basic text editors or older terminals.
A modified tinytable object.
RevealJS presentation theme
theme_revealjs( x, css = get_option("tinytable_revealjs_css", default = "light"), fontsize = get_option("tinytable_revealjs_fontsize", default = 0.8), fontsize_caption = get_option("tinytable_revealjs_fontsize_caption", default = 1) )theme_revealjs( x, css = get_option("tinytable_revealjs_css", default = "light"), fontsize = get_option("tinytable_revealjs_fontsize", default = 0.8), fontsize_caption = get_option("tinytable_revealjs_fontsize_caption", default = 1) )
x |
A |
css |
String. CSS theme: "light" (default) or "dark". |
fontsize |
Numeric. Font size multiplier for table content. |
fontsize_caption |
Numeric. Font size multiplier for table captions. |
A modified tinytable object.
In HTML, rotation is always applied to cell content (not the whole table) to
keep borders intact. In LaTeX and Typst, when i and j are both NULL,
the entire table is rotated; otherwise cell content is rotated.
theme_rotate( x, angle = get_option("tinytable_rotate_angle", default = 90), i = NULL, j = NULL, ... )theme_rotate( x, angle = get_option("tinytable_rotate_angle", default = 90), i = NULL, j = NULL, ... )
x |
A |
angle |
Numeric. Rotation angle in degrees (0-360). |
i |
Row indices for cell rotation. When |
j |
Column indices for cell rotation. When |
... |
Additional arguments (ignored). |
A modified tinytable object.
Striped theme with alternating row colors
theme_striped(x, ...)theme_striped(x, ...)
x |
A |
... |
Additional arguments (ignored). |
A modified tinytable object.
Default theme for TinyTable
theme_tinytable(x, ...)theme_tinytable(x, ...)
x |
A tinytable object. |
... |
Additional arguments are ignored. |
A modified tinytable object.
DEPRECATED: The theme_tt() function has been deprecated. Please use the format-specific or style-specific theme functions instead.
theme_tt(x, theme, ...)theme_tt(x, theme, ...)
x |
deprecated |
theme |
deprecated |
... |
Additional arguments |
Throws an informative error message
Typst-specific styles and options
theme_typst( x, multipage = get_option("tinytable_typst_multipage", default = FALSE), figure = get_option("tinytable_typst_figure", default = TRUE), portable = get_option("tinytable_typst_portable", default = NULL), align_figure = get_option("tinytable_typst_align_figure", NULL), resize_width = get_option("tinytable_typst_resize_width", 1), resize_height = get_option("tinytable_typst_resize_height", default = NULL), resize_direction = get_option("tinytable_typst_resize_direction", default = NULL), ... )theme_typst( x, multipage = get_option("tinytable_typst_multipage", default = FALSE), figure = get_option("tinytable_typst_figure", default = TRUE), portable = get_option("tinytable_typst_portable", default = NULL), align_figure = get_option("tinytable_typst_align_figure", NULL), resize_width = get_option("tinytable_typst_resize_width", 1), resize_height = get_option("tinytable_typst_resize_height", default = NULL), resize_direction = get_option("tinytable_typst_resize_direction", default = NULL), ... )
x |
A |
multipage |
Logical. When |
figure |
Logical, whether to wrap the table in a Typst figure environment and block. |
portable |
Logical. Sets whether to create portable Typst output with base64-encoded local images embedded directly in the Typst code. Remote image URLs are not downloaded. |
align_figure |
Character string indicating horizontal alignment: "l", "c", or "r".
Defaults to |
resize_width |
Numeric value between 0.01 and 1.0 specifying the target width as a fraction of the available Typst layout width when resize_direction is specified. |
resize_height |
Numeric value between 0.01 and 1.0 specifying the target height as a fraction of the available Typst layout height. When specified, height controls the scaling and width scales proportionally. |
resize_direction |
Character string specifying how to resize tables. Options are: "down" to shrink oversized tables, "up" to expand undersized tables, and "both" to always scale to the target size. |
... |
Additional arguments. |
The tt function renders a table in different formats with various styling options: HTML, Markdown, LaTeX, Word, PDF, PNG, or Typst. The table can be customized with additional functions:
style_tt(): style fonts, colors, alignment, etc.
format_tt(): format numbers, dates, strings, etc.
group_tt(): row or column group labels.
save_tt(): save the table to a file or return the table as a string.
print(): print to a specific format, ex: print(x, "latex")
theme_*() functions apply a collection of format-specific or visual transformations to a tinytable.
tinytable attempts to determine the appropriate way to print the table based on interactive use, RStudio availability, and output format in RMarkdown or Quarto documents. Users can call print(x, output="markdown") to print the table in a specific format. Alternatively, they can set a global option: options("tinytable_print_output"="markdown")
tt(x, ...) ## Default S3 method: tt( x, digits = get_option("tinytable_tt_digits", default = NULL), caption = get_option("tinytable_tt_caption", default = NULL), notes = get_option("tinytable_tt_notes", default = NULL), width = get_option("tinytable_tt_width", default = NULL), height = get_option("tinytable_tt_height", default = NULL), theme = get_option("tinytable_tt_theme", default = "default"), colnames = get_option("tinytable_tt_colnames", default = TRUE), rownames = get_option("tinytable_tt_rownames", default = FALSE), escape = get_option("tinytable_tt_escape", default = FALSE), ... )tt(x, ...) ## Default S3 method: tt( x, digits = get_option("tinytable_tt_digits", default = NULL), caption = get_option("tinytable_tt_caption", default = NULL), notes = get_option("tinytable_tt_notes", default = NULL), width = get_option("tinytable_tt_width", default = NULL), height = get_option("tinytable_tt_height", default = NULL), theme = get_option("tinytable_tt_theme", default = "default"), colnames = get_option("tinytable_tt_colnames", default = TRUE), rownames = get_option("tinytable_tt_rownames", default = FALSE), escape = get_option("tinytable_tt_escape", default = FALSE), ... )
x |
A data frame, data table, or tibble to be rendered as a table. |
... |
Additional arguments are ignored |
digits |
Number of significant digits to keep for numeric variables. When |
caption |
A string that will be used as the caption of the table. This argument should not be used in Quarto or Rmarkdown documents. In that context, please use the appropriate chunk options. |
notes |
Notes to append to the bottom of the table. This argument accepts several different inputs:
|
width |
Table or column width.
|
height |
Row height in em units. Single numeric value greater than zero that determines the row height spacing. |
theme |
Function or string.
|
colnames |
|
rownames |
Logical. If |
escape |
Logical. If |
An object of class tt representing the table.
The table object has S4 slots which hold information about the structure of the table. For example, the table@group_index_i slot includes the row indices for grouping labels added by group_tt().
Warning: Relying on or modifying the contents of these slots is strongly discouraged. Their names and contents could change at any time, and the tinytable developers do not consider changes to the internal structure of the output object to be a "breaking change" for versioning or changelog purposes.
.pdf output requires a full LaTeX installation on the local computer.
.png output requires the webshot2 package.
.html self-contained files and theme_typst(portable = TRUE) require the base64enc package.
tinytable uses the tabularray package from your LaTeX distribution to draw tables. tabularray, in turn, uses the special tblr, talltblr, and longtblr environments.
When rendering a document from Quarto or Rmarkdown directly to PDF, tinytable will populate the LaTeX preamble automatically with all the required packages. For standalone LaTeX documents, these commands should be inserted in the preamble manually:
Note: Your document will fail to compile to PDF in Quarto if you enable caching and you use tinytable due to missing LaTeX headers. To avoid this problem, set the option #| cache: false for the chunk(s) where you use tinytable.
\usepackage{tabularray}
\usepackage{float}
\usepackage{graphicx}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\UseTblrLibrary{siunitx}
\newcommand{\tinytableTabularrayUnderline}[1]{\underline{#1}}
\newcommand{\tinytableTabularrayStrikeout}[1]{\sout{#1}}
\NewTableCommand{\tinytableDefineColor}[3]{\definecolor{#1}{#2}{#3}}
Markdown is a text-only format that only supports these styles: italic, bold, strikeout. The width argument is also unavailable.
These limitations exist because there is no standard markdown syntax for the other styling options.
However, in terminals (consoles) that support it, tinytable can display colors and text styles using
ANSI escape codes by setting theme_markdown(ansi = TRUE). This allows for rich formatting in
compatible terminal environments.
Word tables only support these styles: italic, bold, strikeout. The width argument is also unavailable.
Moreover, the style_tt() function cannot be used to style headers inserted by the group_tt() function;
instead, you should style the headers directly in the header definition using markdown syntax:
group_tt(i = list("*italic header*" = 2)). These limitations are due to the fact that we create
Word documents by converting a markdown table to .docx via the Pandoc software, which requires
going through a text-only intermediate format.
Experimental Feature: The Tabulator.js integration is experimental and the API may change in future versions.
The Tabulator.js library provides powerful interactive table features including sorting, filtering, pagination, data export, and real-time editing capabilities. This theme customizes the appearance and behavior of Tabulator tables.
Features:
Sorting and filtering of all columns
Pagination with configurable page sizes
Search functionality across all columns
Multiple CSS themes and custom styling
Real-time data export options
Accessibility features (ARIA compliant)
Limitations:
style_tt() supports most styling options (bold, italic, color, background, fontsize, etc.) with cell-level precision. Styles persist across sorting and pagination. Column-wide alignment only (row-specific align/alignv with i argument not supported)
Row-based formatting (format_tt() with i argument) not supported
Global stylesheets affect all tables in multi-table documents
Date formatting uses Luxon tokens, not R's strptime format
Boolean formatting requires format_tt() with bool argument for custom display
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.
Nearly all of the package's functions retrieve their default values from global options. This allows you to set defaults once and apply them to all tables without needing to specify them each time. For example, to fix the the digits argument of the tt() function globally, call:
options(tinytable_tt_digits = 4)
In addition, some more specific options are available to control the behavior of the package in specific contexts.
tinytable_html_mathjax: Insert MathJax scripts (warning: may conflict if MathJax is loaded elsewhere)
tinytable_pdf_clean: Delete temporary and log files for pdf output in save_tt()
tinytable_color_name_normalization: Enable/disable automatic color name processing (default: TRUE). When enabled, R color names recognized by col2rgb() are converted to hex format for consistent rendering across HTML, LaTeX, and Typst formats. If R color conversion fails, LaTeX color names are used as fallback. Colors explicitly supplied as hex values with "#" prefix are passed through unchanged. Set to FALSE to disable processing and pass color names unchanged.
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
Example of Quarto-specific code in cells:
x <- data.frame(Math = "x^2^", Citation = "@Lovelace1842")
fn <- function(z) sprintf("<span data-qmd='%s'></span>", z)
tt(x) |> format_tt(i = 1, fn = fn)
For more details on Quarto table processing: https://quarto.org/docs/authoring/tables.html#disabling-quarto-table-processing
The specified order of operations used when building tables is defined in the build.R file, which can be viewed on Github: https://github.com/vincentarelbundock/tinytable/tree/main/R
A few important things to note:
The i and j indices in format_tt() and style_tt() refer to the table structure after any grouping operations have been applied.
The theme argument in tt() is applied before any other theme, and pre-empts the default theme.
Theme functions apply transformations immediately when they are called, but they can delay the execution of certain operations using internal helpers: build_prepare() and build_finalize(). See theme_*() files in the Github repository for examples.
rbind() and rbind2() combine two tinytable objects before formatting. In some cases, this has the undesirable consequence of coercing numeric variables to character, which prevents further numeric formatting. To avoid this, users can apply format_tt() directly to the data frames before calling tt().
library(tinytable) x <- mtcars[1:4, 1:5] tt(x) tt(x, theme = "striped", width = 0.5, caption = "Data about cars." ) tt(x, notes = "Hello World!") fn <- list(i = 0:1, j = 2, text = "Hello World!") tab <- tt(x, notes = list("*" = fn)) print(tab, "latex") k <- data.frame(x = c(0.000123456789, 12.4356789)) tt(k, digits = 2) # use variable labels stored in attributes as column names dat = mtcars[1:5, c("cyl", "mpg", "hp")] attr(dat$cyl, "label") <- "Cylinders" attr(dat$mpg, "label") <- "Miles per Gallon" attr(dat$hp, "label") <- "Horse Power" tt(dat, colnames = "label")library(tinytable) x <- mtcars[1:4, 1:5] tt(x) tt(x, theme = "striped", width = 0.5, caption = "Data about cars." ) tt(x, notes = "Hello World!") fn <- list(i = 0:1, j = 2, text = "Hello World!") tab <- tt(x, notes = list("*" = fn)) print(tab, "latex") k <- data.frame(x = c(0.000123456789, 12.4356789)) tt(k, digits = 2) # use variable labels stored in attributes as column names dat = mtcars[1:5, c("cyl", "mpg", "hp")] attr(dat$cyl, "label") <- "Cylinders" attr(dat$mpg, "label") <- "Miles per Gallon" attr(dat$hp, "label") <- "Horse Power" tt(dat, colnames = "label")