Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

autoformat

Automatically Format Export Tables


Description

Suggest an appropriate alignment, number of digits, and display type for xtable.

Usage

autoformat(xtab, zap = getOption("digits"))

xalign(x, pad = TRUE)
xdigits(x, pad = TRUE, zap = getOption("digits"))
xdisplay(x, pad = TRUE)

Arguments

xtab

an object of class xtable.

x

a vector, matrix, or data frame.

pad

whether to format row names, when x is two-dimensional.

zap

the number of digits passed to zapsmall.

Value

autoformat returns a copy of xtab, after applying xalign, xdigits, and xdisplay.

xalign returns a character vector consisting of "l" and "r" elements, for left/right alignment.

xdigits returns an integer vector.

xdisplay returns a character vector of "d", "f", and "s" elements, for integer/double/string display.

Author(s)

Arni Magnusson.

See Also

Examples

## 1  Vector
xalign(precip)
xdigits(precip)
xdisplay(precip)


## 2  Data frame
head(mtcars)
xdigits(mtcars, pad = FALSE)
xdigits(mtcars, pad = TRUE)
xalign(mtcars)
xdisplay(mtcars)


## 3  Autoformat when xtable is created
xtable(mtcars, align = xalign(mtcars), digits = xdigits(mtcars),
       display = xdisplay(mtcars))

## equivalent shortcut
xtable(mtcars, auto = TRUE)


## 4  Autoformat existing xtable
mt <- xtable(mtcars)
align(mt) <- xalign(mt)
digits(mt) <- xdigits(mt)
display(mt) <- xdisplay(mt)

## equivalent shortcut
mt <- autoformat(mt)

xtable

Export Tables to LaTeX or HTML

v1.8-4
GPL (>= 2)
Authors
David B. Dahl [aut], David Scott [aut, cre], Charles Roosen [aut], Arni Magnusson [aut], Jonathan Swinton [aut], Ajay Shah [ctb], Arne Henningsen [ctb], Benno Puetz [ctb], Bernhard Pfaff [ctb], Claudio Agostinelli [ctb], Claudius Loehnert [ctb], David Mitchell [ctb], David Whiting [ctb], Fernando da Rosa [ctb], Guido Gay [ctb], Guido Schulz [ctb], Ian Fellows [ctb], Jeff Laake [ctb], John Walker [ctb], Jun Yan [ctb], Liviu Andronic [ctb], Markus Loecher [ctb], Martin Gubri [ctb], Matthieu Stigler [ctb], Robert Castelo [ctb], Seth Falcon [ctb], Stefan Edwards [ctb], Sven Garbade [ctb], Uwe Ligges [ctb]
Initial release
2019-04-08

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.