%\VignettePackage{xtable}\r
% !Rnw weave = knitr\r
% \VignetteEngine{knitr::knitr}\r
-\r
%**************************************************************************\r
-%\r
-% # $Id:$\r
-\r
-% $Revision: $\r
-% $Author: $\r
-% $Date: $\r
-\r
-\r
\documentclass[article, nojss]{jss}\r
\usepackage{amsthm}\r
\usepackage{amsmath}\r
\usepackage{afterpage}\r
\usepackage{hyperref}\r
\r
-\title{\r
-The \pkg{xtable} Gallery\r
-}\r
-\author{Jonathan Swinton and others\\\r
- <jonathan@swintons.net>\r
-}\r
-\r
+\title{The \pkg{xtable} Gallery}\r
+\author{Jonathan Swinton and others\\<jonathan@swintons.net>}\r
\Plainauthor{Jonathan Swinton, and others} %% comma-separated\r
-\r
\Plaintitle{The xtable Gallery} %% without formatting\r
-\r
\Shorttitle{\pkg{xtable} Gallery} %% a short title (if necessary)\r
\r
<<include=FALSE>>=\r
library(knitr)\r
-opts_chunk$set(\r
-fig.path='figdir/fig', debug=TRUE, echo=TRUE\r
-)\r
+opts_chunk$set(fig.path='figdir/fig', debug=TRUE, echo=TRUE)\r
options(replace.assign = TRUE, width = 60,\r
tidy.opts = list(width.cutoff = 60))\r
@\r
%\usepackage{hyperref}\r
\r
\Abstract{\r
-\r
This document gives a gallery of tables which can be made by using\r
the \texttt{xtable} package to create \LaTeX\ output. It doubles as\r
a regression check for the package.\r
-\r
}\r
\r
\Keywords{Reproducible research, \LaTeX}\r
-\r
-\Address{\r
- Jonathan Swinton\\\r
- E-mail: \email{jonathan@swintons.net}\r
-}\r
+\Address{Jonathan Swinton\\E-mail: \email{jonathan@swintons.net}}\r
\r
\begin{document}\r
\r
-\r
-\r
\section{Gallery}\r
+\r
\subsection{Data frame}\r
Load example dataset\r
<<>>=\r
<<results='asis'>>=\r
fm1.table\r
@\r
+\r
\subsection{lm}\r
<<>>=\r
fm2 <- lm(tlimth ~ sex*ethnicty, data = tli)\r
xtable(anova(fm2b, fm2))\r
@\r
\r
-\r
\subsection{glm}\r
-\r
<<>>=\r
-\r
## Demonstrate glm\r
fm3 <- glm(disadvg ~ ethnicty*grade, data = tli, family = binomial())\r
fm3.table <- xtable(fm3)\r
xtable(anova(fm3))\r
@\r
\r
-\r
\subsection{More aov}\r
<<>>=\r
-\r
## Demonstrate aov\r
## Taken from help(aov) in R 1.1.1\r
## From Venables and Ripley (1997) p.210.\r
xtable(npk.aovE)\r
@\r
\r
-\r
<<results='asis'>>=\r
xtable(summary(npk.aovE))\r
@\r
\r
\subsection{More lm}\r
<<>>=\r
-\r
## Demonstrate lm\r
## Taken from help(lm) in R 1.1.1\r
## Annette Dobson (1990) "An Introduction to Generalized Linear Models".\r
xtable(lm.D9)\r
@\r
\r
-\r
<<results='asis'>>=\r
xtable(anova(lm.D9))\r
@\r
\r
\subsection{More glm}\r
<<>>=\r
-\r
## Demonstrate glm\r
## Taken from help(glm) in R 1.1.1\r
## Annette Dobson (1990) "An Introduction to Generalized Linear Models".\r
xtable(pr1)\r
@\r
\r
-\r
<<results='asis'>>=\r
xtable(summary(pr1))\r
@\r
\r
-\r
-\r
<<echo = FALSE, results = 'Hide'>>=\r
# ## Demonstrate princomp\r
# ## Taken from help(princomp) in mva package of R 1.1.1\r
@\r
\r
\subsection{Time series}\r
-\r
<<>>=\r
temp.ts <- ts(cumsum(1 + round(rnorm(100), 0)),\r
start = c(1954, 7), frequency = 12)\r
Now change the default alignment, digits and display using helper functions\r
\texttt{xalign}, \texttt{xdigits}, and \texttt{xdisplay}.\r
\r
-\r
<<proposed>>=\r
align(x) <- xalign(x)\r
digits(x) <- xdigits(x)\r
x\r
@ %def\r
\r
-\r
-\r
\section{Sanitization}\r
<<>>=\r
insane <- data.frame(Name = c("Ampersand","Greater than","Less than",\r
@\r
\r
\subsection{Markup in tables}\r
-\r
Markup can be included in tables, including in column and row names, by using\r
a custom \code{sanitize.text.function()}:\r
\r
@\r
\r
\section{Format examples}\r
+\r
\subsection{Adding a centering environment }\r
<<results='asis'>>=\r
print(xtable(lm.D9, caption = "\\tt latex.environments = NULL"),\r
print(xtable(lm.D9, caption = "\\tt latex.environments = \"center\""),\r
latex.environments = "center")\r
@\r
-\subsection{Column alignment}\r
\r
+\subsection{Column alignment}\r
<<>>=\r
tli.table <- xtable(tli[1:10, ])\r
@\r
@\r
\r
\subsection{Significant digits}\r
-\r
-\r
Specify with a single argument\r
<<>>=\r
digits(tli.table) <- 3\r
tli.table\r
@\r
\r
-\r
\vspace{12pt}\r
or one for each column, counting the row names,\r
<<>>=\r
@\r
\r
\subsection{Horizontal lines}\r
-\r
\vspace{12pt}\textbf{\itshape Line locations}\r
\r
Use the \texttt{hline.after} argument to specify the position of the\r
print(bktbs, booktabs = TRUE, hline.after = hlines)\r
@\r
\r
-\r
\subsection{Table-level LaTeX}\r
<<results='asis'>>=\r
print(xtable(anova(glm.D93)), size = "small")\r
@\r
\r
-\r
\subsection{Long tables}\r
Remember to insert \verb|\usepackage{longtable}| in your \LaTeX preamble.\r
\r
<<longtable>>=\r
-\r
## Demonstration of longtable support.\r
x <- matrix(rnorm(1000), ncol = 10)\r
x.big <- xtable(x, label = 'tabbig',\r
\section{Acknowledgements}\r
Most of the examples in this gallery are taken from the \texttt{xtable}\r
documentation.\r
+\r
\section{R Session information}\r
<<results='asis'>>=\r
toLatex(sessionInfo())\r
@\r
+\r
\end{document}\r