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

toLatex-ftableR Documentation

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.

cattablines() is a small auxiliary function which creates rows of a LaTeX table from a given matrix.

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)

cattablines(x, rsep = "\\\\", csep = " & ", include.rownames = TRUE)

Arguments

object

an ftable to be converted to a LaTeX table. This is accomplished via formatting it.

x

for fftable() an ftable object; for tablines() a character matrix with attributes nrv and ncv (as returned by fftable()) giving the number of row and column variables, respectively; for cattablines() a numeric or character matrix.

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]")), or NULL (default).

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

character

a vector containing the lines of the header.

NA

do not construct a header.

NULL

construct a default header.

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, a suitable default is constructed.

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", "Large", "LARGE", "huge", or "Huge").

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.

include.rownames

logical indicating whether row names are included in the first column.

...

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

body

character vector of lines of the table body.

body.raw

character matrix of cells of the table body.

head

character vector of lines of the table head.

head.raw

character matrix of cells of the table head..

align

alignment string.

rsepcol

character vector containing the row separators (last entries of each row).

cattablines() outputs the formatted lines for copy-and-paste into a LaTeX table.

Author(s)

Marius Hofert and Martin Maechler.

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

## 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)

## ``poor-man's approach'' for creating lines of a LaTeX table
set.seed(271)
tab <- matrix(runif(6), ncol=3)
ftab <- formatC(tab, digits=4, format="f")
cattablines(ftab)
rownames(ftab) <- LETTERS[1:nrow(ftab)]
cattablines(ftab)

simsalapar documentation built on April 27, 2023, 9:05 a.m.