xtable_summary: Create And Print Tables With Markup

Description Usage Arguments Details Value Author(s) See Also Examples

Description

The function produces objects which can be printed to LaTeX and HTML code.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## S3 method for class 'summary'
xtable(x, caption = NULL, label = NULL, align = NULL,
       digits = NULL, display = NULL, ...)

## S3 method for class 'xtable.summary'
print(x, rules = NULL, header = NULL,
      caption.placement = getOption("xtable.caption.placement", "top"),
      hline.after = getOption("xtable.hline.after", NULL),
      include.rownames = FALSE,
      add.to.row = getOption("xtable.add.to.row", NULL),
      booktabs = getOption("xtable.booktabs", TRUE),
      sanitize.text.function = get_option(x, "sanitize"),
      math.style.negative = getOption("xtable.math.style.negative", TRUE),
      math.style.exponents = getOption("xtable.math.style.exponents", TRUE),
      tabular.environment = getOption("xtable.tabular.environment", "tabular"),
      floating = getOption("xtable.floating", FALSE),
      latex.environments = getOption("xtable.latex.environments", c("center")),
      ...)

Arguments

x

object of class "summary", which is produced by the function summarize or an object of class "xtable.summary" produced by xtable.

caption

character vector specifying the table's caption; see xtable for details.

label

character string specifying the LaTeX label or HTML anchor; see xtable for details.

align

character string specifying the alignment of table columns; see xtable for details.

digits

numeric vector specifying the number of digits to display in each column; see xtable for details.

display

character string specifying the column types; see xtable for details.

rules

character string specifying the rules to be used. Per default the rules are defined by summarize and subsequently extracted from x via get_option(x, "rules").

header

character string specifying the table header to be used. Per default the header is defined by summarize and subsequently extracted from x via get_option(x, "header").

caption.placement

can be either "bottom" or "top" (default). Note that the standard default of print.xtable is "bottom".

hline.after

vector indicating the rows after which a horizontal line is printed. Here, the default is to not draw hlines (i.e. hline.after = NULL) and horizontal lines are added via add.to.row (see there for details). Note that the standard default of print.xtable is c(-1,0,nrow(x)).

add.to.row

list of row numbers (pos) and text (command) to be added to the specified rows. Per default, top and bottom rules are added to the table and a rule specified in rules is added below the heading. If sep = TRUE in summarize additional separators (as specified in rules) are added after each variable.

include.rownames

logical. Always set to FALSE.

booktabs

logical. If TRUE (default), the toprule, midrule and bottomrule tags from the LaTeX package "booktabs" are used rather than hline for the horizontal line tags. Note that the standard default of print.xtable is FALSE.

sanitize.text.function

All non-numeric enteries (except row and column names) are sanitised in an attempt to remove characters which have special meaning for the output format. Per default the function toLatex is used to sanitize the text. For more options see print.xtable.

math.style.negative

logical. If TRUE (default) the negative sign is wrapped in dollar signs for LaTeX tables. Note that the standard default of print.xtable is FALSE.

math.style.exponents

logical. If TRUE (default) scientific numers are set as exponents. See print.xtable for details. Note that the standard default of print.xtable is FALSE.

tabular.environment

character string. Per default "tabular" is used. For long tables that span over more than one page, one can use "longtable". For more options see print.xtable.

floating

logical. Determine if the table is printed in a floating environment. Note that the standard default of print.xtable is TRUE. See there for details.

latex.environments

character string. Per default "center" is used. In contrast to the default behavior of print.xtable, tables are also centered if no floating environment is used. For details and more options see print.xtable.

...

additional arguments passed to xtable or print.xtable. See there for details.

Details

We use the standard xtable function but add a special class that allows different defaults in the print.xtable function.

In general, all options of print.xtable can be used as well as global options set via options(). E.g. options(xtable.booktabs = FALSE will set the argument booktabs per default to FALSE for all calls to print.xtable.

Value

After printing, a table with LaTeX markup is returned.

Author(s)

Benjamin Hofner

See Also

For details see xtable and print.xtable.

summarize, get_option

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
if (require("nlme")) {
    ## Use dataset Orthodont
    data(Orthodont, package = "nlme")

    ## Get summary for continuous variables
    (tab1 <- summarize(Orthodont, type = "numeric"))

    ## Get summary for categorical variables
    (tab2 <- summarize(Orthodont, type = "fac"))

    ## Using the tables with LaTeX
    if (require("xtable")) {
        xtable(tab1)
        ## grouped table
        xtable(summarize(Orthodont, group = "Sex"))
        xtable(tab2)
    }
}

Example output

Loading required package: car
Loading required package: xtable

Attaching package: 'papeR'

The following object is masked from 'package:utils':

    toLatex

Loading required package: nlme
Factors are dropped from the summary
Non-factors are dropped from the summary
Factors are dropped from the summary
%% Output requires \usepackage{booktabs}.
\begin{center}
% latex table generated in R 3.4.1 by xtable 1.8-2 package
% Thu Aug  2 10:45:30 2018
\begin{tabular}{llrrr}
  \toprule
   & Level &   & N & \% \\ 
    \cmidrule{2-2} \cmidrule{4-5} 
 Subject & M16 &  &   4 & 3.7 \\ 
   & M05 &  &   4 & 3.7 \\ 
   & M02 &  &   4 & 3.7 \\ 
   & M11 &  &   4 & 3.7 \\ 
   & M07 &  &   4 & 3.7 \\ 
   & M08 &  &   4 & 3.7 \\ 
   & M03 &  &   4 & 3.7 \\ 
   & M12 &  &   4 & 3.7 \\ 
   & M13 &  &   4 & 3.7 \\ 
   & M14 &  &   4 & 3.7 \\ 
   & M09 &  &   4 & 3.7 \\ 
   & M15 &  &   4 & 3.7 \\ 
   & M06 &  &   4 & 3.7 \\ 
   & M04 &  &   4 & 3.7 \\ 
   & M01 &  &   4 & 3.7 \\ 
   & M10 &  &   4 & 3.7 \\ 
   & F10 &  &   4 & 3.7 \\ 
   & F09 &  &   4 & 3.7 \\ 
   & F06 &  &   4 & 3.7 \\ 
   & F01 &  &   4 & 3.7 \\ 
   & F05 &  &   4 & 3.7 \\ 
   & F07 &  &   4 & 3.7 \\ 
   & F02 &  &   4 & 3.7 \\ 
   & F08 &  &   4 & 3.7 \\ 
   & F03 &  &   4 & 3.7 \\ 
   & F04 &  &   4 & 3.7 \\ 
   & F11 &  &   4 & 3.7 \\ 
     \cmidrule{2-2} \cmidrule{4-5} 
Sex & Male &  &  64 & 59.3 \\ 
   & Female &  &  44 & 40.7 \\ 
   \bottomrule
\end{tabular}
\end{center}

papeR documentation built on March 23, 2021, 1:08 a.m.