EVOLUTION-MANAGER
Edit File: xtableFtable.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Create and Export Flat Tables</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for xtableFtable {xtable}"><tr><td>xtableFtable {xtable}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2> Create and Export Flat Tables </h2> <h3>Description</h3> <p><code>xtableFtable</code> creates an object which contains information about a flat table which can be used by <code>print.xtableFtable</code> to produce a character string which when included in a document produces a nicely formatted flat table. </p> <h3>Usage</h3> <pre> 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()), ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>For <code>xtableFtable</code>, an object of class <code>"ftable"</code>. For <code>print.xtableFtable</code>, an object of class <code>c("xtableFtable", "ftable")</code>.</p> </td></tr> <tr valign="top"><td><code>caption</code></td> <td> <p>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 <code>NULL</code> to suppress the caption. Default value is <code>NULL</code>. </p> </td></tr> <tr valign="top"><td><code>label</code></td> <td> <p>Character vector of length 1 containing the LaTeX label or HTML anchor. Set to <code>NULL</code> to suppress the label. Default value is <code>NULL</code>. </p> </td></tr> <tr valign="top"><td><code>align</code></td> <td> <p>Character vector of length equal to the number of columns of the resulting table, indicating the alignment of the corresponding columns. Also, <code>"|"</code> may be used to produce vertical lines between columns in LaTeX tables, but these are effectively ignored when considering the required length of the supplied vector. If a character vector of length one is supplied, it is split as <code>strsplit(align, "")[[1]]</code> before processing. For a flat table, the number of columns is the number of columns of data, plus the number of row variables in the table, plus one for the row names, even though row names are not printed. Use <code>"l"</code>, <code>"r"</code>, and <code>"c"</code> to denote left, right, and center alignment, respectively. Use <code>"p{3cm}"</code> etc. for a LaTeX column of the specified width. For HTML output the <code>"p"</code> alignment is interpreted as <code>"l"</code>, ignoring the width request. If <code>NULL</code> all row variable labels will be left aligned, separated from the data columns by a vertical line, and all data columns will be right aligned. The actual length of <code>align</code> depends on the value of <code>method</code>.</p> </td></tr> <tr valign="top"><td><code>digits</code></td> <td> <p>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 <code>digits</code> is negative, the corresponding columns are displayed in scientific format with <code>abs(digits)</code> digits.</p> </td></tr> <tr valign="top"><td><code>display</code></td> <td> <p>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 <code>formatC</code> function. Use <code>"d"</code> (for integers), <code>"f"</code>, <code>"e"</code>, <code>"E"</code>, <code>"g"</code>, <code>"G"</code>, <code>"fg"</code> (for reals), or <code>"s"</code> (for strings). <code>"f"</code> gives numbers in the usual <code>xxx.xxx</code> format; <code>"e"</code> and <code>"E"</code> give <code>n.ddde+nn</code> or <code>n.dddE+nn</code> (scientific format); <code>"g"</code> and <code>"G"</code> put <code>x[i]</code> into scientific format only if it saves space to do so. <code>"fg"</code> uses fixed format as <code>"f"</code>, but <code>digits</code> as number of <em>significant</em> digits. Note that this can lead to quite long result strings. If <code>NULL</code> all row variable names and labels will have format <code>"s"</code>, and all data columns will have format <code>"d"</code>. The actual length of <code>display</code> depends on the value of <code>method</code>.</p> </td></tr> <tr valign="top"><td><code>quote</code></td> <td> <p>A character string giving the set of quoting characters for <code>format.ftable</code> used in <code>print.xtableFtable</code>. To disable quoting altogether, use <code>quote=""</code>.</p> </td></tr> <tr valign="top"><td><code>method</code></td> <td> <p>String specifying how the <code>"xtableFtable"</code> object is printed in the <code>print</code> method. Can be abbreviated. Available methods are (see the examples in <code><a href="../../stats/html/read.ftable.html">print.ftable</a></code>): </p> <dl> <dt>"non.compact"</dt><dd><p>the default representation of an <code>"ftable"</code> object.</p> </dd> <dt>"row.compact"</dt><dd><p>a row-compact version without empty cells below the column labels.</p> </dd> <dt>"col.compact"</dt><dd><p>a column-compact version without empty cells to the right of the row labels.</p> </dd> <dt>"compact"</dt><dd><p>a row- and column-compact version. This may imply a row and a column label sharing the same cell. They are then separated by the string <code>lsep</code>.</p> </dd> </dl> </td></tr> <tr valign="top"><td><code>lsep</code></td> <td> <p>Only for <code>method = "compact"</code>, the separation string for row and column labels.</p> </td></tr> <tr valign="top"><td><code>type</code></td> <td> <p>Type of table to produce. Possible values for <code>type</code> are <code>"latex"</code> or <code>"html"</code>. Default value is <code>"latex"</code> and is the only type implemented so far.</p> </td></tr> <tr valign="top"><td><code>file</code></td> <td> <p>Name of file where the resulting code should be saved. If <code>file=""</code>, output is displayed on screen. Note that the function also (invisibly) returns a character vector of the results (which can be helpful for post-processing). Default value is <code>""</code>.</p> </td></tr> <tr valign="top"><td><code>append</code></td> <td> <p>If <code>TRUE</code> and <code>file!=""</code>, code will be appended to <code>file</code> instead of overwriting <code>file</code>. Default value is <code>FALSE</code>.</p> </td></tr> <tr valign="top"><td><code>floating</code></td> <td> <p>If <code>TRUE</code> and <code>type="latex"</code>, the resulting table will be a floating table (using, for example, <code>\begin{table}</code> and <code>\end{table}</code>). See <code>floating.environment</code> below. Default value is <code>TRUE</code>. </p> </td></tr> <tr valign="top"><td><code>floating.environment</code></td> <td> <p>If <code>floating=TRUE</code> and <code>type="latex"</code>, the resulting table uses the specified floating environment. Possible values include <code>"table"</code>, <code>"table*"</code>, and other floating environments defined in LaTeX packages. Default value is <code>"table"</code>.</p> </td></tr> <tr valign="top"><td><code>table.placement</code></td> <td> <p>If <code>floating=TRUE</code> and <code>type="latex"</code>, the floating table will have placement given by <code>table.placement</code> where <code>table.placement</code> must be <code>NULL</code> or contain only elements of {"h","t","b","p","!","H"}. Default value is <code>"ht"</code>.</p> </td></tr> <tr valign="top"><td><code>caption.placement</code></td> <td> <p>The caption will be placed at the bottom of the table if <code>caption.placement</code> is <code>"bottom"</code> and at the top of the table if it equals <code>"top"</code>. Default value is <code>"bottom"</code>.</p> </td></tr> <tr valign="top"><td><code>caption.width</code></td> <td> <p>The caption will be placed in a <code>"parbox"</code> of the specified width if <code>caption.width</code> is not <code>NULL</code> and <code>type="latex"</code>. Default value is <code>NULL</code>.</p> </td></tr> <tr valign="top"><td><code>latex.environments</code></td> <td> <p>If <code>floating=TRUE</code> and <code>type="latex"</code>, the specified LaTeX environments (provided as a character vector) will enclose the tabular environment. Default value is <code>"center"</code>. </p> </td></tr> <tr valign="top"><td><code>tabular.environment</code></td> <td> <p>When <code>type="latex"</code>, the tabular environment that will be used. When working with tables that extend more than one page, using <code>tabular.environment="longtable"</code> with the corresponding LaTeX package (see Fairbairns, 2005) allows one to typeset them uniformly. Note that <code>floating</code> should be set to <code>FALSE</code> when using the <code>longtable</code> environment. Default value is <code>"tabular"</code>.</p> </td></tr> <tr valign="top"><td><code>size</code></td> <td> <p>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 <code>NULL</code>. </p> </td></tr> <tr valign="top"><td><code>hline.after</code></td> <td> <p>When <code>type="latex"</code>, a vector of numbers between -1 and <code>nrow(x)</code>, inclusive, indicating the rows after which a horizontal line should appear. Repeated values are allowed. If <code>NULL</code> the default is to draw a line before before starting the table, after the column variable names and labels, and at the end of the table.</p> </td></tr> <tr valign="top"><td><code>NA.string</code></td> <td> <p>String to be used for missing values in table entries. Default value is <code>""</code>.</p> </td></tr> <tr valign="top"><td><code>only.contents</code></td> <td> <p>If <code>TRUE</code> only the rows of the table are printed. Default value is <code>FALSE</code>. </p> </td></tr> <tr valign="top"><td><code>add.to.row</code></td> <td> <p>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 <code>NULL</code>, i.e. do not add commands.</p> </td></tr> <tr valign="top"><td><code>sanitize.text.function</code></td> <td> <p>Since the table entries are counts no sanitization is necessary. The default is <code>as.is</code>, which is the function which makes no changes. This also applies to the labels for the row and column variables since these are also part of the table which is printed using a call to <code>print.xtable</code>.</p> </td></tr> <tr valign="top"><td><code>sanitize.rownames.function</code></td> <td> <p>Like the <code>sanitize.text.function</code>, but applicable to row names. The default uses the <code>sanitize.text.function</code>. </p> </td></tr> <tr valign="top"><td><code>sanitize.colnames.function</code></td> <td> <p>Like the <code>sanitize.text.function</code>, but applicable to column names. The default uses the <code>sanitize.text.function</code>. </p> </td></tr> <tr valign="top"><td><code>math.style.negative</code></td> <td> <p>In a LaTeX table, if <code>TRUE</code>, then use $-$ for the negative sign (as was the behavior prior to version 1.5-3). Default value is <code>FALSE</code>.</p> </td></tr> <tr valign="top"><td><code>math.style.exponents</code></td> <td> <p>In a LaTeX table, if <code>TRUE</code> or <code>"$$"</code>, then use <code style="white-space: pre;">$5 \times 10^{5}$</code> for 5e5. If <code>"ensuremath"</code>, then use <code style="white-space: pre;">\ensuremath{5 \times 10^{5}}</code> for 5e5. If <code>"UTF-8"</code> or <code>"UTF-8"</code>, then use UTF-8 to approximate the LaTeX typesetting for 5e5. Default value is <code>FALSE</code>.</p> </td></tr> <tr valign="top"><td><code>html.table.attributes</code></td> <td> <p>In an HTML table, attributes associated with the <code><TABLE></code> tag. Default value is <code>"border=1"</code>.</p> </td></tr> <tr valign="top"><td><code>print.results</code></td> <td> <p>If <code>TRUE</code>, the generated table is printed to standard output. Set this to <code>FALSE</code> if you will just be using the character vector that is returned invisibly. Default value is <code>TRUE</code>.</p> </td></tr> <tr valign="top"><td><code>format.args</code></td> <td> <p>List of arguments for the <code>formatC</code> function. For example, standard German number separators can be specified as <code>format.args=list(big.mark = "'", decimal.mark = ","))</code>. The arguments <code>digits</code> and <code>format</code> should not be included in this list. Default value is <code>NULL</code>.</p> </td></tr> <tr valign="top"><td><code>rotate.rownames</code></td> <td> <p>If <code>TRUE</code>, the row names and labels, and column variable names are displayed vertically in LaTeX. Default value is <code>FALSE</code>.</p> </td></tr> <tr valign="top"><td><code>rotate.colnames</code></td> <td> <p>If <code>TRUE</code>, the column names and labels, and row variable names are displayed vertically in LaTeX. Default value is <code>FALSE</code>.</p> </td></tr> <tr valign="top"><td><code>booktabs</code></td> <td> <p>If <code>TRUE</code>, the <code>toprule</code>, <code>midrule</code> and <code>bottomrule</code> commands from the LaTeX "booktabs" package are used rather than <code>hline</code> for the horizontal line tags. </p> </td></tr> <tr valign="top"><td><code>scalebox</code></td> <td> <p>If not <code>NULL</code>, a <code>scalebox</code> clause will be added around the tabular environment with the specified value used as the scaling factor. Default value is <code>NULL</code>.</p> </td></tr> <tr valign="top"><td><code>width</code></td> <td> <p>If not <code>NULL</code>, the specified value is included in parentheses between the tabular environment <code>begin</code> tag and the alignment specification. This allows specification of the table width when using tabular environments such as <code>tabular*</code> and <code>tabularx</code>. Note that table width specification is not supported with the <code>tabular</code> or <code>longtable</code> environments. Default value is <code>NULL</code>.</p> </td></tr> <tr valign="top"><td><code>comment</code></td> <td> <p>If <code>TRUE</code>, the version and timestamp comment is included. Default value is <code>TRUE</code>. </p> </td></tr> <tr valign="top"><td><code>timestamp</code></td> <td> <p>Timestamp to include in LaTeX comment. Set this to <code>NULL</code> to exclude the timestamp. Default value is <code>date()</code>. </p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Additional arguments. (Currently ignored.) </p> </td></tr> </table> <h3>Details</h3> <p><code>xtableFtable</code> 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 <code>method</code>. It uses the results of those calculations to set sensible values for <code>align</code> and <code>display</code> 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 <code>c("xtableFtable", "ftable")</code>. </p> <p><code>print.xtableFtable</code> uses the attributes attached to an object of class <code>c("xtableFtable", "ftable")</code> to create a suitable character matrix object for subsequent printing. Formatting is carried out by changing the class of the <code>c("xtableFtable", "ftable")</code> to <code>"ftable"</code> then using the generic <code>format</code> to invoke <code>format.ftable</code>, from the <span class="pkg">stats</span> package. The matrix object produced is then printed via a call to <code>print.xtable</code>. </p> <p>Note that at present there is no code for <code>type = "html"</code>. </p> <h3>Value</h3> <p>For <code>xtableFtable</code> an object of class <code>c("xtableFtable", "ftable")</code>, with attributes </p> <table summary="R valueblock"> <tr valign="top"><td><code>ftableCaption</code></td> <td> <p>the value of the <code>caption</code> argument</p> </td></tr> <tr valign="top"><td><code>ftableLabel</code></td> <td> <p>the value of the <code>label</code> argument</p> </td></tr> <tr valign="top"><td><code>ftableAlign</code></td> <td> <p>the value of the <code>label</code> argument</p> </td></tr> <tr valign="top"><td><code>ftableDigits</code></td> <td> <p>the value of the <code>digits</code> argument or the default value if <code>digits = NULL</code></p> </td></tr> <tr valign="top"><td><code>quote</code></td> <td> <p>the value of the <code>quote</code> argument</p> </td></tr> <tr valign="top"><td><code>ftableDisplay</code></td> <td> <p>the value of the <code>display</code> argument or the default value if <code>align = NULL</code></p> </td></tr> <tr valign="top"><td><code>method</code></td> <td> <p>the value of the <code>method</code> argument</p> </td></tr> <tr valign="top"><td><code>lsep</code></td> <td> <p>the value of the <code>lsep</code> argument</p> </td></tr> <tr valign="top"><td><code>nChars</code></td> <td> <p>a vector of length 2 giving the number of character rows and the number of character columns</p> </td></tr> </table> <p>For <code>print.xtableFtable</code> a character string which will produce a formatted table when included in a LaTeX document. </p> <h3>Note</h3> <p>The functions <code>xtableFtable</code> and <code>print.xtableFtable</code> are new and their behaviour may change in the future based on user experience and recommendations. </p> <p>It is not recommended that users change the values of <code>align</code>, <code>digits</code> or <code>align</code>. 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 <code>xtableFtable</code> and/or <code>print.xtableFtable</code>. </p> <h3>Author(s)</h3> <p>David Scott <a href="mailto:d.scott@auckland.ac.nz">d.scott@auckland.ac.nz</a>. </p> <h3>References</h3> <p>Fairbairns, Robin (2005) <em>Tables longer than a single page.</em> The UK List of TeX Frequently Asked Questions on the Web. <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=longtab">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=longtab</a> </p> <h3>See Also</h3> <p><code><a href="../../stats/html/ftable.html">ftable</a></code>, <code><a href="../../stats/html/read.ftable.html">print.ftable</a></code> </p> <p><code><a href="xtable.html">xtable</a></code>, <code><a href="table.attributes.html">caption</a></code>, <code><a href="table.attributes.html">label</a></code>, <code><a href="table.attributes.html">align</a></code>, <code><a href="table.attributes.html">digits</a></code>, <code><a href="table.attributes.html">display</a></code>, <code><a href="../../base/html/formatc.html">formatC</a></code> </p> <h3>Examples</h3> <pre> 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) </pre> <hr /><div style="text-align: center;">[Package <em>xtable</em> version 1.8-4 <a href="00Index.html">Index</a>]</div> </body></html>