fable: The mythical formatted table generator.

Description Usage Arguments Value Methods (by class) Examples

View source: R/fable.R

Description

Creates formatted HTML tables of in a flexible, convenient way.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
fable(x, ...)

## S3 method for class 'data.frame'
fable(x, value, facets, ..., render, lab,
  expand.along = c("rows", "columns"), drop = c("both", "rows",
  "columns", "none"), collapse.cells = TRUE, row.names = T)

## S3 method for class 'formula'
fable(x, data, ..., render, lab,
  expand.along = c("rows", "columns"), drop = c("both", "rows",
  "columns", "none"), collapse.cells = TRUE)

## S3 method for class 'numeric'
fable(x, rowvars, colvars, ..., render, lab,
  expand.along = c("rows", "columns"), drop = c("both", "rows",
  "columns", "none"), collapse.cells = TRUE)

## S3 method for class 'ftable'
fable(x, text = matrix(as.character(x), nrow(x)), ...,
  lab, drop = c("both", "rows", "columns", "none"),
  collapse.cells = TRUE)

Arguments

x

An object.

...

Additional arguments passed to render.

value

A column name or position.

facets

A two-sided formula of the form r1 + r2 ~ c1 + c2 where r1, r2 specify row variables and c1, c2 column variables for splitting the data.

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.

expand.along

Specify the direction to expand the table when render returns a (named) vector.

drop

If TRUE (the default), rows and columns with zero counts will be dropped.

collapse.cells

If TRUE (the default), row/column header cells will be collapsed (merged) where appropriate.

row.names

If TRUE (the default), row names will be shown in the first column of the table. Set to FALSE to suppress row names. Only applies when displaying whole data.frame.

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.

Value

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.

Methods (by class)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# mtcars examples
fable(mtcars)
fable(mtcars, mpg, facets=(gear ~ cyl), lab="Cylinders")
fable(mpg ~ gear | cyl, data=mtcars, lab="Cylinders")
fable(rownames(mtcars) ~ gear | cyl, data=mtcars,
  render=paste, collapse="<br/>", lab="Cylinders")

# OrchardSprays examples
fable(head(OrchardSprays, 12))
fable(head(OrchardSprays, 12), row.names=FALSE)
fable(treatment ~ rowpos | colpos, data=OrchardSprays, lab="colpos")
fable(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)
fable(decrease ~ treatment, data=OrchardSprays, render=rndr.meansd, expand.along="rows")
fable(decrease ~ treatment, data=OrchardSprays, render=rndr.meansd, expand.along="columns")

# ToothGrowth examples
fable(len ~ dose | supp, data=ToothGrowth, lab="Mean (SD)",
  render=function(x) sprintf("%0.3g (%0.3g)", mean(x), sd(x)))

fable(len ~ dose | supp, data=ToothGrowth, lab="Supplement Type",
  render=rndr.meansd)

fable(len ~ dose | supp, data=ToothGrowth, lab="Supplement Type",
  render=rndr.meansd, expand.along="columns")

benjaminrich/fable documentation built on June 19, 2021, 5:43 a.m.