| Title: | 'SciViews::R' - Create Tabular Outputs from R |
|---|---|
| Description: | Create rich-formatted tabular outputs from R that can be incorporated into R Markdown/Quarto documents with correct output at least in HTML, LaTeX/PDF, Word and PowerPoint formats for various R objects. |
| Authors: | Philippe Grosjean [aut, cre] (ORCID: <https://orcid.org/0000-0002-2694-9471>), Guyliann Engels [aut] (ORCID: <https://orcid.org/0000-0001-9514-1014>) |
| Maintainer: | Philippe Grosjean <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.7.1 |
| Built: | 2026-05-10 09:18:38 UTC |
| Source: | https://github.com/SciViews/tabularise |
Create rich-formatted tabular outputs from various R objects that can be incorporated into R Markdown/Quarto documents with correct output at least in HTML, LaTeX/PDF, Word and PowerPoint for various R objects.
For an object class, there is a "default" method that creates the most
obvious tabular form for this object, but there might be also other types
provided with different tabular views of the same object. All types are
accessible from the tabularise() function that accepts type= argument,
or better, by using the compact and easier to read tabularise$type() form.
tabularise() constructs a table (flextable object by default, or
tinytable object with kind = "tt").
Stb a collection of functions to manipulate and format a table (mostly functions from the {flextable} package.
colformat_sci() and colformat_md() are additional columns formatters for
flextable objects, respectively, scientific and markdown formats.
para_md() creates {flextable} paragraphs with rich-formatting by
converting Markdown strings into such {flextable} paragraphs.
Maintainer: Philippe Grosjean [email protected] (ORCID)
Authors:
Guyliann Engels [email protected] (ORCID)
Useful links:
Report bugs at https://github.com/SciViews/tabularise/issues
Scientific format for columns in {flextable}
colformat_md( x, i = NULL, j = NULL, h.sizes = c(15, 13, 9), h.colors = c("black", "darkgray"), strike = list(color = h.colors[2], underlined = FALSE), bullet = "·", code.font = "monospace", code.shading = "#f8f8f8", link.color = "blue", link.underline = TRUE, autolink = TRUE )colformat_md( x, i = NULL, j = NULL, h.sizes = c(15, 13, 9), h.colors = c("black", "darkgray"), strike = list(color = h.colors[2], underlined = FALSE), bullet = "·", code.font = "monospace", code.shading = "#f8f8f8", link.color = "blue", link.underline = TRUE, autolink = TRUE )
x |
a flextable object |
i |
rows selection |
j |
columns selection |
h.sizes |
font sizes for titles |
h.colors |
font colors for titles |
strike |
a list with color and underlined = |
bullet |
bullet character used for lists |
code.font |
font used for code strings |
code.shading |
background color (shading) for code strings |
link.color |
color used for URL links |
link.underline |
are URL links underlined? |
autolink |
are links automatically constructed when there is an URL in the text? |
the flextable object with the selected region formatted as markdown strings.
dat <- data.frame( x = 1:3, y = noquote(c("#### text1", "text~2~", "text^3^")), names = noquote(c("*Iris setosa*", "Iris ~~virginica~~", "Iris **versicolor**")), id = c("*setosa*", "`virginica`", "**versicolor**"), factor = factor(c("*setosa*", "`virginica`", "**versicolor**")) ) tabularise(dat) tabularise(dat) |> colformat_md() |> Stb$autofit() tabularise(dat) |> colformat_md(i = 2:3, j = 'names') |> Stb$autofit()dat <- data.frame( x = 1:3, y = noquote(c("#### text1", "text~2~", "text^3^")), names = noquote(c("*Iris setosa*", "Iris ~~virginica~~", "Iris **versicolor**")), id = c("*setosa*", "`virginica`", "**versicolor**"), factor = factor(c("*setosa*", "`virginica`", "**versicolor**")) ) tabularise(dat) tabularise(dat) |> colformat_md() |> Stb$autofit() tabularise(dat) |> colformat_md(i = 2:3, j = 'names') |> Stb$autofit()
Scientific format for columns in {flextable}
colformat_sci( x, i = NULL, j = NULL, digits = 3, scipen = 0, lod = NULL, lod_str = paste("<", lod), fancy = TRUE, op = c("·", "×", "*", "x") )colformat_sci( x, i = NULL, j = NULL, digits = 3, scipen = 0, lod = NULL, lod_str = paste("<", lod), fancy = TRUE, op = c("·", "×", "*", "x") )
x |
a flextable object |
i |
rows selection |
j |
columns selection |
digits |
number of digits to display |
scipen |
penalty to use to decide if numbers are presented in decimal or scientific notation (generally use 0 or -1) |
lod |
value indicating the limit of detection, for which we should display something like '< lod_value' instead of the actual value; useful for p values (R often uses 2e-16 in that case), chemical measurements ... |
lod_str |
the string to use, by default, it is |
fancy |
use a perfect scientific notation ( |
op |
the operator character to use in fancy scientific notation |
the flextable object with the selected region formatted as scientific numbers.
summ <- summary(lm(Volume ~ Girth + Height, data = trees)) tabularise(as.data.frame(summ$coefficients)) |> colformat_sci() |> colformat_sci(j = 'Pr(>|t|)', lod = 2e-16) |> Stb$autofit()summ <- summary(lm(Volume ~ Girth + Height, data = trees)) tabularise(as.data.frame(summ$coefficients)) |> colformat_sci() |> colformat_sci(j = 'Pr(>|t|)', lod = 2e-16) |> Stb$autofit()
Create a rich-formatted paragraph using markdown notation for flextable objects
para_md( ..., h.fonts = rep(flextable::get_flextable_defaults()$font.family, 6), h.sizes = c(15, 13, 9), h.colors = c("black", "darkgray"), strike.color = h.colors[2], strike.underline = NA, code.font = "inconsolata", code.shading = "#f8f8f8", link.color = "blue", link.underline = TRUE, bullet = "·", autolink = TRUE, smart = TRUE, debug = FALSE ) ## S3 method for class 'paragraph' print(x, ...)para_md( ..., h.fonts = rep(flextable::get_flextable_defaults()$font.family, 6), h.sizes = c(15, 13, 9), h.colors = c("black", "darkgray"), strike.color = h.colors[2], strike.underline = NA, code.font = "inconsolata", code.shading = "#f8f8f8", link.color = "blue", link.underline = TRUE, bullet = "·", autolink = TRUE, smart = TRUE, debug = FALSE ) ## S3 method for class 'paragraph' print(x, ...)
... |
the character strings with markdown formatting |
h.fonts |
fonts used for the titles (h1-h6) |
h.sizes |
font sizes for titles |
h.colors |
font colors for titles |
strike.color |
color for strikethrough text |
strike.underline |
is strikethrough text converted into underlined text? |
code.font |
font used for code strings |
code.shading |
background color (shading) for code strings |
link.color |
color used for URL links |
link.underline |
are URL links underlined? |
bullet |
bullet character used for lists |
autolink |
are links automatically constructed when there is an URL in the text? |
smart |
is smart punctuation detected and replaced? |
debug |
switch in debug mode |
x |
A paragraph object |
a flextable paragraph object with its content formatted according to markdown tags
md1 <- paste0("# Heading **1**\n## Heading **2**\n### Heading **3**\n", "#### Heading **4**\n##### Heading **5**\n###### Heading **6**") md2 <- paste0("* List 1\n 1. List 1a\n 2. List 1b\n* List 2\n<br />\n", "*Some text* with super^script^, sub~script~ and ~~color~~{+#F50490}") tabularise(head(iris)) |> Stb$add_footer_lines(para_md(md1, md2))md1 <- paste0("# Heading **1**\n## Heading **2**\n### Heading **3**\n", "#### Heading **4**\n##### Heading **5**\n###### Heading **6**") md2 <- paste0("* List 1\n 1. List 1a\n 2. List 1b\n* List 2\n<br />\n", "*Some text* with super^script^, sub~script~ and ~~color~~{+#F50490}") tabularise(head(iris)) |> Stb$add_footer_lines(para_md(md1, md2))
This set provides all the functions you can use to manipulate tabularise()
tables. They mostly contain the {flextable} API. You are supposed to
use it like Stb$verb(....) where verb is one of the objects contained in
the collection. Use Stb to list all objects in the set.
StbStb
An object of class list of length 147.
When printing Stb alone, a list of all verbs and other objects
provided in the set are returned.
# TODO...# TODO...
Tabularise an object (arrange or enter in tabular form)
tabularise(data, ..., type = "default", kind = "ft", env = parent.frame()) tabularize(data, ..., type = "default", kind = "ft", env = parent.frame())tabularise(data, ..., type = "default", kind = "ft", env = parent.frame()) tabularize(data, ..., type = "default", kind = "ft", env = parent.frame())
data |
An object |
... |
Further arguments (depending on the object class and on |
type |
The type of table to produce. |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate formulas (you probably do not need to change the default). |
A flextable object you can print in different form or rearrange with the {flextable} functions from set Stb$verb().
tabularise_default(), tabularise_headtail(), tabularise_coef(),
tabularise_tidy(), tabularise_glance()
tabularise(iris)tabularise(iris)
The "coef" type of tabularise() extracts and formats a table of
coefficients from an object, similar to stats::coef() applied to the same
object, but in a rich-formatted form.
tabularise_coef(data, ..., kind = "ft", env = env) ## Default S3 method: tabularise_coef(data, ..., kind = "ft", env = env)tabularise_coef(data, ..., kind = "ft", env = env) ## Default S3 method: tabularise_coef(data, ..., kind = "ft", env = env)
data |
An object |
... |
Further arguments (depending on the object class). |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate formulas (you probably do not need to change the default). |
No useful method for this type is defined in the {tabularise} package, but additional packages might define some.
A flextable object you can print in different form or rearrange with the {flextable} functions from set Stb$verb().
The "confint" type of tabularise() presents a table of confidence intervals
for an objects (e.g., confidence intervals on parameters of a model). This is
similar to the output of stats::confint() generic function on the same
object. The nicely formatted table obtained here is (almost)
publication-ready (good for informal reports, notebooks, etc).
tabularise_confint(data, ..., kind = "ft", env = env) ## Default S3 method: tabularise_confint(data, ..., kind = "ft", env = env)tabularise_confint(data, ..., kind = "ft", env = env) ## Default S3 method: tabularise_confint(data, ..., kind = "ft", env = env)
data |
An object |
... |
Further arguments (depending on the object class). |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate formulas (you probably do not need to change the default). |
#' No useful method for this type is defined in the {tabularise} package, but additional packages might define some.
A flextable object you can print in different form or rearrange with the {flextable} functions from set Stb$verb().
tabularise(), stats::confint()
The "default" type is the most obvious tabular representation for an object.
For data frames, it tabularises the first few rows and columns (so, in case
of a very large object, output remains limited). See also the "headtail" type
that creates a table with the few first and last rows of the table (see
tabularise_headtail()).
tabularise_default(data, ..., kind = "ft", env = parent.frame()) ## Default S3 method: tabularise_default(data, ..., kind = "ft", env = parent.frame()) ## S3 method for class 'data.frame' tabularise_default( data, formula = NULL, col_keys = names(data), cwidth = 0.75, cheight = 0.25, max.rows = 50, max.cols = 15, auto.labs = TRUE, ..., env = parent.frame() ) ## S3 method for class 'matrix' tabularise_default( data, col_keys = colnames(data), rownames = " ", cwidth = 0.75, cheight = 0.25, ..., env = parent.frame() ) ## S3 method for class 'Correlation' tabularise_default( data, col_keys = colnames(data), rownames = " ", header = TRUE, title = header, footer = TRUE, cwidth = 0.75, cheight = 0.25, lang = getOption("SciViews_lang", "en"), ..., env = parent.frame() )tabularise_default(data, ..., kind = "ft", env = parent.frame()) ## Default S3 method: tabularise_default(data, ..., kind = "ft", env = parent.frame()) ## S3 method for class 'data.frame' tabularise_default( data, formula = NULL, col_keys = names(data), cwidth = 0.75, cheight = 0.25, max.rows = 50, max.cols = 15, auto.labs = TRUE, ..., env = parent.frame() ) ## S3 method for class 'matrix' tabularise_default( data, col_keys = colnames(data), rownames = " ", cwidth = 0.75, cheight = 0.25, ..., env = parent.frame() ) ## S3 method for class 'Correlation' tabularise_default( data, col_keys = colnames(data), rownames = " ", header = TRUE, title = header, footer = TRUE, cwidth = 0.75, cheight = 0.25, lang = getOption("SciViews_lang", "en"), ..., env = parent.frame() )
data |
An object |
... |
Further arguments (depending on the object class). |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate formulas (you probably do not need to change the default). |
formula |
A formula to create a table using the {tables} syntax |
col_keys |
The names/keys to use for the table columns |
cwidth |
Initial width for cell sizes in inches |
cheight |
Initial height for cell sizes in inches |
max.rows |
The maximum number of rows to display in the table |
max.cols |
The maximum number of columns to display in the table |
auto.labs |
Are labels automatically used for names of table columns? |
rownames |
col_keys to use for row names. If |
header |
do we add a header? |
title |
do we add a title? |
footer |
do we add a footer? |
lang |
the natural language to use. The default value can be set with,
e.g., |
A flextable object you can print in different form or rearrange with the {flextable} functions from set Stb$verb().
tabularise(), tabularise_headtail()
tabularise$default(iris) # Same as simply: tabularise(iris)tabularise$default(iris) # Same as simply: tabularise(iris)
The "glance" type of tabularise() usually presents a very short (mostly
single row) summary of an object in a rich-formatted table. The table
presents usually the same or very similar information to what would be
obtained with the generics::glance() generic function on the same object.
The nicely formatted table obtained here is (almost) publication-ready (good
for informal reports, notebooks, etc).
tabularise_glance(data, ..., kind = "ft", env = env) ## Default S3 method: tabularise_glance(data, ..., kind = "ft", env = env)tabularise_glance(data, ..., kind = "ft", env = env) ## Default S3 method: tabularise_glance(data, ..., kind = "ft", env = env)
data |
An object |
... |
Further arguments (depending on the object class). |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate formulas (you probably do not need to change the default). |
#' No useful method for this type is defined in the {tabularise} package, but additional packages might define some.
A flextable object you can print in different form or rearrange with the {flextable} functions from set Stb$verb().
tabularise(), generics::glance()
The "headtail" type for tabularise presents the first (head) and last (tail)
few lines of a table. This is useful for a long table and often more useful
than just displaying only the first few lines of the same table (that you got
with the default type, see tabularise_default()).
tabularise_headtail(data, n = 10, ..., kind = "ft", env = env) ## Default S3 method: tabularise_headtail(data, n = 10, ..., kind = "ft", env = env) ## S3 method for class 'data.frame' tabularise_headtail( data, n = 10, auto.labs = TRUE, sep = "...", ..., lang = getOption("SciViews_lang", "en"), kind = "ft", env = env )tabularise_headtail(data, n = 10, ..., kind = "ft", env = env) ## Default S3 method: tabularise_headtail(data, n = 10, ..., kind = "ft", env = env) ## S3 method for class 'data.frame' tabularise_headtail( data, n = 10, auto.labs = TRUE, sep = "...", ..., lang = getOption("SciViews_lang", "en"), kind = "ft", env = env )
data |
An object |
n |
The number of lines to display in the (truncated) table. |
... |
Further arguments (depending on the object class). |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate formulas (you probably do not need to change the default). |
auto.labs |
Are labels automatically used for names of table columns? |
sep |
The separator between the first and last lines of a table. By default, the vertical ellipse shape is used. |
lang |
the natural language to use. The default value can be set with,
e.g., |
A flextable object you can print in different form or rearrange with the {flextable} functions from set Stb$verb().
tabularise(), head(), tail(), tabularise_default()
tabularise$headtail(iris)tabularise$headtail(iris)
The "tidy" type of tabularise() presents a tidy version of an object, as
it could be obtained by generics::tidy() whose goal is to turn information
contained in an object into a rectangular table. Here, the table is nicely
formatted as an (almost) publication-ready form (good for informal reports,
notebooks, etc).
tabularise_tidy(data, ..., kind = "ft", env = env) ## Default S3 method: tabularise_tidy(data, ..., kind = "ft", env = env)tabularise_tidy(data, ..., kind = "ft", env = env) ## Default S3 method: tabularise_tidy(data, ..., kind = "ft", env = env)
data |
An object |
... |
Further arguments (depending on the object class). |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate formulas (you probably do not need to change the default). |
No useful method for this type is defined in the {tabularise} package, but additional packages might define some.
A flextable object you can print in different form or rearrange with the {flextable} functions from set Stb$verb().
tabularise(), generics::tidy()
This theme is applied by default to {tinytable} output. One can use a
different one with tinytable::theme_tt().
theme_tt_sciviews(x, ...)theme_tt_sciviews(x, ...)
x |
A tinytable object |
... |
Additional arguments (not used) |
A tinytable object with the default SciViews theme applied