Learn R Programming

simsalapar (version 1.0-2)

toLatex-ftable: Convert Flat Contingency Table (ftable) and VarLists to LaTeX Table

Description

The ftable method of toLatex() converts an ftable to a LaTeX table via tablines().

Analogously, the varlist method of toLatex() converts an varlist to a LaTeX table.

fftable() essentially calls format.ftable() and adds attributes ncv and nrv to the return object.

tablines() computes ingredients for converting a character matrix with attributes to a LaTeX table.

Usage

## S3 method for class 'ftable':
toLatex(object, vList = NULL,
        x.escape = FALSE, exprFUN = expr2latex, escapeFUN = escapeLatex,
        align = NULL, booktabs = TRUE, head = NULL,
	rsep = "\\\\\\\\", sp = if(booktabs) 3 else 1.25, rsep.sp = NULL,
	csep = " & ", quote = FALSE, lsep=" \\textbar\\ ",
	do.table = TRUE, placement = "htbp", center = TRUE,
	fontsize = "normalsize", caption = NULL, label = NULL, ...)

## S3 method for class 'varlist': toLatex(object, col.vars = c("Variable", "expression", "type", "value"), exprFUN = expr2latex, escapeFUN = escapeLatex, align = NULL, booktabs = TRUE, head = NULL, rsep = "\\\\", sp = if(booktabs) 3 else 1.25, rsep.sp = NULL, csep = " & ", do.table = TRUE, placement = "htbp", center = TRUE, fontsize = "normalsize", caption = NULL, label = NULL, ...)

fftable(x, lsep = " | ", quote = FALSE, method = "compact", ...)

tablines(x, align = NULL, booktabs = TRUE, head = NULL, rsep = "\\\\", sp = if(booktabs) 3 else 1.25, rsep.sp = NULL, csep = " & ", quote = FALSE)

Arguments

object
an ftable to be converted to a LaTeX table. This is accomplished via formatting it.
x
for fftable() a character matrix; for tablines() a character
vList
a variable specification list see varlist.
x.escape
logical indicating if the body entries of the table should be escaped by espaceFUN(); if false, as by default, only the column and row variables are escaped.
exprFUN
a function, by default expr2latex, for transforming plotmath expressions to equivalent LaTeX strings.
escapeFUN
a function, by default escapeLatex which escapes each of its input character strings to valid LaTeX strings.
align
either a character (e.g., "*{3}{c} S[table-format=1.2]") or character vector (e.g., c("c", "c", "c", "S[table-format=1.2]")
booktabs
logical indicating whether a LaTeX table in the format of the LaTeX booktabs package is created (requires the LaTeX booktabs package loaded in the preamble).
head
either [object Object],[object Object],[object Object]
rsep
character to be inserted at the end of each row.
sp
numeric scaling factor for separating blocks of rows if rsep.sp is NULL.
rsep.sp
numeric of length equal to the number of different groups of rows minus one, giving the spaces (interpreted as pt) between different groups of rows. If NULL
csep
character string for separating different cells in a row.
quote, lsep, method
see format.ftable() (R-3.0.0 or later).
col.vars
character vector of length 3 or 4 ("expression" can be omitted), specifying the column names.
do.table
logical indicating whether a LaTeX table environment should be used at all.
placement
(if do.table:) character string containing a LaTeX table placement string such as "htbp".
center
logical indicating whether centering should happen.
fontsize
character string giving a fontsize (such as "tiny", "scriptsize", "footnotesize", "small", "normalsize", "large",
caption
(if do.table:) character string containing the table caption or NULL for no caption.
label
(if do.table:) character string containing the table label or NULL for no label.
...
additional arguments passed to format.ftable().

Value

  • toLatex() returns an object as from wrapLaTable().

    fftable() returns a formatted flat contingency table as returned by format.ftable() with added attributes ncv (number of column variables) and nrv (number of row variables).

    tablines() a list with components

  • bodycharacter vector of lines of the table body.
  • body.rawcharacter matrix of cells of the table body.
  • headcharacter vector of lines of the table head.
  • head.rawcharacter matrix of cells of the table head..
  • alignalignment string.
  • rsepcolcharacter vector containing the row separators (last entries of each row).

References

see simsalapar-package.

See Also

wrapLaTable() for how to wrap the lines of a LaTeX table created by tablines() in a LaTeX table and tabular environment.

Examples

Run this code
## Different table layouts for the same content
(ft1 <- ftable(Titanic, col.vars = 1:4))
(ft2 <- ftable(Titanic, row.vars = 1))
(ft3 <- ftable(Titanic, row.vars = 1:2))
(ft4 <- ftable(Titanic, row.vars = 1:3))
(ft5 <- ftable(Titanic, row.vars = 1:4))

## What tablines() returns
tablines(fftable(ft2))

## LaTeX (booktabs/non-booktabs) versions
toLatex(ft1, do.table=FALSE)
toLatex(ft1, booktabs=FALSE)
toLatex(ft1, method="col.compact")
toLatex(ft1)
toLatex(ft2)
toLatex(ft3)
toLatex(ft4)
toLatex(ft5, booktabs=FALSE)
toLatex(ft5, method="col.compact")
toLatex(ft5)

Run the code above in your browser using DataLab