xtableFtable {xtable} | R Documentation |
Create and Export Flat Tables
Description
xtableFtable
creates an object which contains information about
a flat table which can be used by print.xtableFtable
to produce
a character string which when included in a document produces a nicely
formatted flat table.
Usage
xtableFtable(x, caption = NULL, label = NULL,
align = NULL, digits = 0, display = NULL,
quote = FALSE,
method = c("non.compact", "row.compact",
"col.compact", "compact"),
lsep = " $\\vert$ ", ...)
## S3 method for class 'xtableFtable'
print(x,
type = getOption("xtable.type", "latex"),
file = getOption("xtable.file", ""),
append = getOption("xtable.append", FALSE),
floating = getOption("xtable.floating", TRUE),
floating.environment = getOption("xtable.floating.environment", "table"),
table.placement = getOption("xtable.table.placement", "ht"),
caption.placement = getOption("xtable.caption.placement", "bottom"),
caption.width = getOption("xtable.caption.width", NULL),
latex.environments = getOption("xtable.latex.environments", c("center")),
tabular.environment = getOption("xtable.tabular.environment", "tabular"),
size = getOption("xtable.size", NULL),
hline.after = getOption("xtable.hline.after", NULL),
NA.string = getOption("xtable.NA.string", ""),
only.contents = getOption("xtable.only.contents", FALSE),
add.to.row = getOption("xtable.add.to.row", NULL),
sanitize.text.function = getOption("xtable.sanitize.text.function", as.is),
sanitize.rownames.function = getOption("xtable.sanitize.rownames.function",
sanitize.text.function),
sanitize.colnames.function = getOption("xtable.sanitize.colnames.function",
sanitize.text.function),
math.style.negative = getOption("xtable.math.style.negative", FALSE),
math.style.exponents = getOption("xtable.math.style.exponents", FALSE),
html.table.attributes = getOption("xtable.html.table.attributes",
"border=1"),
print.results = getOption("xtable.print.results", TRUE),
format.args = getOption("xtable.format.args", NULL),
rotate.rownames = getOption("xtable.rotate.rownames", FALSE),
rotate.colnames = getOption("xtable.rotate.colnames", FALSE),
booktabs = getOption("xtable.booktabs", FALSE),
scalebox = getOption("xtable.scalebox", NULL),
width = getOption("xtable.width", NULL),
comment = getOption("xtable.comment", TRUE),
timestamp = getOption("xtable.timestamp", date()),
...)
Arguments
x |
For |
caption |
Character vector of length 1 or 2 containing the
table's caption or title. If length is 2, the second item is the
"short caption" used when LaTeX generates a "List of Tables". Set to
|
label |
Character vector of length 1 containing the LaTeX label
or HTML anchor. Set to |
align |
Character vector of length equal to the number of columns
of the resulting table, indicating the alignment of the corresponding
columns. Also, |
digits |
Numeric vector of length equal to one (in which case it will be
replicated as necessary) or to the number of columns in the
resulting table. Since data in the table consists of
counts, the default is 0. If the value of |
display |
Character vector of length equal to the number of columns of the
resulting table, indicating the format for the corresponding columns.
These values are passed to the |
quote |
A character string giving the set of quoting characters
for |
method |
String specifying how the
|
lsep |
Only for |
type |
Type of table to produce. Possible values for |
file |
Name of file where the resulting code should be saved. If
|
append |
If |
floating |
If |
floating.environment |
If |
table.placement |
If |
caption.placement |
The caption will be placed at the bottom
of the table if |
caption.width |
The caption will be placed in a |
latex.environments |
If |
tabular.environment |
When |
size |
A character vector that is inserted just before the
tabular environment starts. This can be used to set the font size
and a variety of other table settings. Initial backslashes are
automatically prefixed, if not supplied by user.
Default value is |
hline.after |
When |
NA.string |
String to be used for missing values in table
entries.
Default value is |
only.contents |
If |
add.to.row |
A list of two components. The first component (which
should be called 'pos') is a list that contains the position of rows on
which extra commands should be added at the end. The second
component (which should be called 'command') is a character vector
of the same length as the first component, which contains the command
that should be added at the end of the specified rows.
Default value is |
sanitize.text.function |
Since the table entries are counts no
sanitization is necessary. The default is |
sanitize.rownames.function |
Like the
|
sanitize.colnames.function |
Like the
|
math.style.negative |
In a LaTeX table, if |
math.style.exponents |
In a LaTeX table, if |
html.table.attributes |
In an HTML table, attributes associated
with the |
print.results |
If |
format.args |
List of arguments for the |
rotate.rownames |
If |
rotate.colnames |
If |
booktabs |
If |
scalebox |
If not |
width |
If not |
comment |
If |
timestamp |
Timestamp to include in LaTeX comment. Set this
to |
... |
Additional arguments. (Currently ignored.) |
Details
xtableFtable
carries out some calculations to determine the
number of rows and columns of names and labels which will be in the
table when formatted as a flat table, which depends on the value of
method
. It uses the results of those calculations to set
sensible values for align
and display
if these have
not been supplied. It attaches attributes to the resulting object
which specify details of the function call which are needed when
printing the resulting object which is of class
c("xtableFtable", "ftable")
.
print.xtableFtable
uses the attributes attached to an object
of class c("xtableFtable", "ftable")
to create a suitable
character matrix object for subsequent printing. Formatting is
carried out by changing the class of the c("xtableFtable",
"ftable")
to "ftable"
then using the generic format
to invoke format.ftable
, from the stats package. The
matrix object produced is then printed via a call to
print.xtable
.
Note that at present there is no code for type = "html"
.
Value
For xtableFtable
an object of class c("xtableFtable",
"ftable")
, with attributes
ftableCaption |
the value of the |
ftableLabel |
the value of the |
ftableAlign |
the value of the |
ftableDigits |
the value of the |
quote |
the value of the |
ftableDisplay |
the value of the |
method |
the value of the |
lsep |
the value of the |
nChars |
a vector of length 2 giving the number of character rows and the number of character columns |
For print.xtableFtable
a character string which will produce a
formatted table when included in a LaTeX document.
Note
The functions xtableFtable
and print.xtableFtable
are
new and their behaviour may change in the future based on user
experience and recommendations.
It is not recommended that users change the values of align
,
digits
or align
. First of all, alternative values have
not been tested. Secondly, it is most likely that to determine
appropriate values for these arguments, users will have to investigate
the code for xtableFtable
and/or print.xtableFtable
.
Author(s)
David Scott d.scott@auckland.ac.nz.
References
Fairbairns, Robin (2005) Tables longer than a single page. The UK List of TeX Frequently Asked Questions on the Web. http://www.tex.ac.uk/cgi-bin/texfaq2html?label=longtab
See Also
xtable
, caption
, label
,
align
, digits
, display
,
formatC
Examples
data(mtcars)
mtcars$cyl <- factor(mtcars$cyl, levels = c("4","6","8"),
labels = c("four","six","eight"))
tbl <- ftable(mtcars$cyl, mtcars$vs, mtcars$am, mtcars$gear,
row.vars = c(2, 4),
dnn = c("Cylinders", "V/S", "Transmission", "Gears"))
xftbl <- xtableFtable(tbl, method = "compact")
print.xtableFtable(xftbl, booktabs = TRUE)
xftbl <- xtableFtable(tbl, method = "row.compact")
print.xtableFtable(xftbl, rotate.colnames = TRUE,
rotate.rownames = TRUE)