| Title: | The Table Tool |
|---|---|
| Description: | Create structured, formatted HTML tables in a flexible and convenient way. |
| Authors: | Benjamin Rich [aut, cre] |
| Maintainer: | Benjamin Rich <[email protected]> |
| License: | GPL-3 |
| Version: | 1.1.1 |
| Built: | 2026-05-28 11:12:53 UTC |
| Source: | https://github.com/benjaminrich/ttt |
knitr contextMethod for printing in a knitr context
## S3 method for class 'ttt' knit_print(x, ..., theme = getOption("ttt.theme"))## S3 method for class 'ttt' knit_print(x, ..., theme = getOption("ttt.theme"))
x |
An object returned by |
... |
Further arguments passed on to |
theme |
A theme (either "default" or "booktabs"). |
Returns a character string. See knitr::knit_print for
how this value is used.
ttt objectPrint ttt object
## S3 method for class 'ttt' print(x, ..., theme = getOption("ttt.theme"))## S3 method for class 'ttt' print(x, ..., theme = getOption("ttt.theme"))
x |
An object returned by |
... |
Further arguments passed on to other |
theme |
A theme (either "default" or "booktabs"). |
In an interactive context, the rendered table will be displayed in a web browser. Otherwise, the HTML code will be printed as text.
Returns x invisibly.
Combine tables vertically
rbind_ttt(...)rbind_ttt(...)
... |
One or more objects returned by |
A character which contains an HTML table fragment. It has
additional class attributes that cause it to be displayed in a browser in an
interactive context, and rendered as HTML in a knitr context.
This function works in a very simple manner, removing certain HTML tags. It may not be completely robust. In particular, the tables being combined need to have the same number of columns.
dat <- fread(text=" ID subject test score 1 Math A 1 1 Math B 2 1 Math C 3 1 Physics D 4 1 Physics E 5 1 Physics F 6 2 Math A 7 2 Math C 8 2 Physics E 9 3 Math C 2 3 Physics D 6 ") rndr.stats <- function(x) { with(table1::stats.apply.rounding(table1::stats.default(x)), { c(N=N, Mean=MEAN, SD=SD) }) } t1 <- ttt(score ~ ID | test + subject, data=dat) t2 <- ttt(score ~ 1 | test + subject, data=dat, render=rndr.stats) rbind_ttt(t1, t2)dat <- fread(text=" ID subject test score 1 Math A 1 1 Math B 2 1 Math C 3 1 Physics D 4 1 Physics E 5 1 Physics F 6 2 Math A 7 2 Math C 8 2 Physics E 9 3 Math C 2 3 Physics D 6 ") rndr.stats <- function(x) { with(table1::stats.apply.rounding(table1::stats.default(x)), { c(N=N, Mean=MEAN, SD=SD) }) } t1 <- ttt(score ~ ID | test + subject, data=dat) t2 <- ttt(score ~ 1 | test + subject, data=dat, render=rndr.stats) rbind_ttt(t1, t2)
ttt stands for “The Table Tool” (or, if you prefer, “Tables! Tables! Tables!”).
It allows you to creates formatted HTML tables of in a flexible and
convenient way.
ttt(x, ...) ## S3 method for class 'data.frame' ttt( x, formula, ..., render, lab, caption, footnote, expand.along = c("rows", "columns"), drop = c("both", "rows", "columns", "none"), collapse.cells = TRUE, topclass = NULL, id = NULL, css = NULL, row.names = TRUE ) ## S3 method for class 'formula' ttt( x, data, ..., render, lab, caption, footnote, expand.along = c("rows", "columns"), drop = c("both", "rows", "columns", "none"), collapse.cells = TRUE, topclass = NULL, id = NULL, css = NULL ) ## S3 method for class 'numeric' ttt( x, rowvars, colvars, ..., render, lab, caption, footnote, expand.along = c("rows", "columns"), drop = c("both", "rows", "columns", "none"), collapse.cells = TRUE, topclass = NULL, id = NULL, css = NULL ) ## S3 method for class 'ftable' ttt( x, text = matrix(as.character(x), nrow(x)), lab, caption, footnote, drop = c("both", "rows", "columns", "none"), collapse.cells = TRUE, html.class = NULL, topclass = NULL, id = NULL, css = NULL, ... )ttt(x, ...) ## S3 method for class 'data.frame' ttt( x, formula, ..., render, lab, caption, footnote, expand.along = c("rows", "columns"), drop = c("both", "rows", "columns", "none"), collapse.cells = TRUE, topclass = NULL, id = NULL, css = NULL, row.names = TRUE ) ## S3 method for class 'formula' ttt( x, data, ..., render, lab, caption, footnote, expand.along = c("rows", "columns"), drop = c("both", "rows", "columns", "none"), collapse.cells = TRUE, topclass = NULL, id = NULL, css = NULL ) ## S3 method for class 'numeric' ttt( x, rowvars, colvars, ..., render, lab, caption, footnote, expand.along = c("rows", "columns"), drop = c("both", "rows", "columns", "none"), collapse.cells = TRUE, topclass = NULL, id = NULL, css = NULL ) ## S3 method for class 'ftable' ttt( x, text = matrix(as.character(x), nrow(x)), lab, caption, footnote, drop = c("both", "rows", "columns", "none"), collapse.cells = TRUE, html.class = NULL, topclass = NULL, id = NULL, css = NULL, ... )
x |
An object. |
... |
Additional arguments passed to |
formula |
A three-part formula of the form |
render |
A function to render the contents of each cell to character data. |
lab |
Specify the contents of an extra table cell spanning over all column labels. |
caption |
A character string to be added as a caption to the table. The default is to omit the caption. |
footnote |
A character string to be added as a footnote to the table. The default is to omit the footnote. |
expand.along |
Specify the direction to expand the table when render returns a (named) vector. |
drop |
If |
collapse.cells |
If |
topclass |
A character string to be used as |
id |
A character string to be used as |
css |
A character string containing CSS code to be added before the
top-level |
row.names |
If |
data |
A data.frame. |
rowvars |
A list of row variables for splitting the data. |
colvars |
A list of column variables for splitting the data. |
text |
A character matrix containing the textual content of each table cell. |
html.class |
A character matrix with the same dimensions as |
A character which contains an HTML table fragment. It has
additional class attributes that cause it to be displayed in a browser in an
interactive context, and rendered as HTML in a knitr context.
ttt(data.frame): The data.frame method.
ttt(formula): The formula method.
ttt(numeric): The numeric method.
ttt(ftable): The ftable method.
# mtcars examples ttt(mtcars) ttt(mtcars, mpg ~ gear | cyl, lab="Cylinders") ttt(mpg ~ gear | cyl, data=mtcars, lab="Cylinders") ttt(rownames(mtcars) ~ gear | cyl, data=mtcars, render=paste, collapse="<br/>", lab="Cylinders") # OrchardSprays examples ttt(head(OrchardSprays, 12)) ttt(head(OrchardSprays, 12), row.names=FALSE) ttt(treatment ~ rowpos | colpos, data=OrchardSprays, lab="colpos") ttt(paste(treatment, decrease, sep="<br/>") ~ rowpos | colpos, data=OrchardSprays, lab="colpos") rndr.meansd <- function(x) formatC(c(Mean=mean(x), SD=sd(x)), digits=3) ttt(decrease ~ treatment, data=OrchardSprays, render=rndr.meansd, expand.along="rows") ttt(decrease ~ treatment, data=OrchardSprays, render=rndr.meansd, expand.along="columns") # ToothGrowth examples ttt(len ~ dose | supp, data=ToothGrowth, lab="Mean (SD)", render=function(x) sprintf("%0.3g (%0.3g)", mean(x), sd(x))) ttt(len ~ dose | supp, data=ToothGrowth, lab="Supplement Type", render=rndr.meansd) ttt(len ~ dose | supp, data=ToothGrowth, lab="Supplement Type", render=rndr.meansd, expand.along="columns")# mtcars examples ttt(mtcars) ttt(mtcars, mpg ~ gear | cyl, lab="Cylinders") ttt(mpg ~ gear | cyl, data=mtcars, lab="Cylinders") ttt(rownames(mtcars) ~ gear | cyl, data=mtcars, render=paste, collapse="<br/>", lab="Cylinders") # OrchardSprays examples ttt(head(OrchardSprays, 12)) ttt(head(OrchardSprays, 12), row.names=FALSE) ttt(treatment ~ rowpos | colpos, data=OrchardSprays, lab="colpos") ttt(paste(treatment, decrease, sep="<br/>") ~ rowpos | colpos, data=OrchardSprays, lab="colpos") rndr.meansd <- function(x) formatC(c(Mean=mean(x), SD=sd(x)), digits=3) ttt(decrease ~ treatment, data=OrchardSprays, render=rndr.meansd, expand.along="rows") ttt(decrease ~ treatment, data=OrchardSprays, render=rndr.meansd, expand.along="columns") # ToothGrowth examples ttt(len ~ dose | supp, data=ToothGrowth, lab="Mean (SD)", render=function(x) sprintf("%0.3g (%0.3g)", mean(x), sd(x))) ttt(len ~ dose | supp, data=ToothGrowth, lab="Supplement Type", render=rndr.meansd) ttt(len ~ dose | supp, data=ToothGrowth, lab="Supplement Type", render=rndr.meansd, expand.along="columns")