]> git.donarmstrong.com Git - xtable.git/blob - pkg/man/autoformat.Rd
Proposal: new function autoformat() and xtable argument auto=TRUE/FALSE
[xtable.git] / pkg / man / autoformat.Rd
1 \name{autoformat}
2 \alias{autoformat}
3 \alias{xalign}
4 \alias{xdigits}
5 \alias{xdisplay}
6 \title{Automatically Format Export Tables}
7 \description{
8   Suggest an appropriate alignment, number of digits, and display type
9   for \code{xtable}.
10 }
11 \usage{
12 autoformat(xtab, zap = getOption("digits"))
13
14 xalign(x, pad = TRUE)
15 xdigits(x, pad = TRUE, zap = getOption("digits"))
16 xdisplay(x, pad = TRUE)
17 }
18 \arguments{
19   \item{xtab}{an object of class \code{xtable}.}
20   \item{x}{a vector, matrix, or data frame.}
21   \item{pad}{whether to format row names, when \code{x} is
22     two-dimensional.}
23   \item{zap}{the number of digits passed to \code{zapsmall}.}
24 }
25 \value{
26   \code{autoformat} returns a copy of \code{xtab}, after applying
27   \code{xalign}, \code{xdigits}, and \code{xdisplay}.
28
29   \code{xalign} returns a character vector consisting of \code{"l"} and
30   \code{"r"} elements, for left/right alignment.
31
32   \code{xdigits} returns an integer vector.
33
34   \code{xdisplay} returns a character vector of \code{"d"}, \code{"f"},
35   and \code{"s"} elements, for integer/double/string display.
36 }
37 \author{Arni Magnusson.}
38 \seealso{
39   \code{\link{xtable}}, \code{\link{align}}, \code{\link{digits}},
40   \code{\link{display}}
41 }
42 \examples{
43 ## 1  Vector
44 xalign(precip)
45 xdigits(precip)
46 xdisplay(precip)
47
48
49 ## 2  Data frame
50 head(mtcars)
51 xdigits(mtcars, pad = FALSE)
52 xdigits(mtcars, pad = TRUE)
53 xalign(mtcars)
54 xdisplay(mtcars)
55
56
57 ## 3  Autoformat when xtable is created
58 xtable(mtcars, align = xalign(mtcars), digits = xdigits(mtcars),
59        display = xdisplay(mtcars))
60
61 ## equivalent shortcut
62 xtable(mtcars, auto = TRUE)
63
64
65 ## 4  Autoformat existing xtable
66 mt <- xtable(mtcars)
67 align(mt) <- xalign(mt)
68 digits(mt) <- xdigits(mt)
69 display(mt) <- xdisplay(mt)
70
71 ## equivalent shortcut
72 mt <- autoformat(mt)
73 }
74 \keyword{array}
75 \keyword{print}