Package: xtable
-Version: 1.8-0
-Date: 2015-10-22
+Version: 1.8-1
+Date: 2015-12-09
Title: Export Tables to LaTeX or HTML
Author: David B. Dahl <dahl@stat.byu.edu>
Maintainer: David Scott <d.scott@auckland.ac.nz>
importFrom("utils", "packageDescription")
export("caption<-", "caption", "label", "label<-",
"align<-", "align", "digits<-", "digits", "display<-",
- "display", "xtable", "print.xtable", "toLatex.xtable",
+ "display", "xtable",
+ "print.xtable", "print.xtableMatharray","toLatex.xtable",
"autoformat", "xalign", "xdigits", "xdisplay")
S3method("print", "xtable")
+S3method("print", "xtableMatharray")
S3method("toLatex", "xtable")
S3method("caption<-", "xtable")
S3method("xtable", "data.frame")
S3method("xtable", "matrix")
+S3method("xtable", "xtableMatharray")
S3method("xtable", "table")
S3method("xtable", "anova")
S3method("xtable", "aov")
+1.8-1 (NOT YET SUBMITTED TO CRAN)
+
1.8-0
* autoformat, xalign, xdigits, xdisplay from Arni Magnusson, added
along with help file. Feature request #5686.
--- /dev/null
+print.xtableMatharray <- function(x,
+ print.results = FALSE,
+ format.args = getOption("xtable.format.args", NULL),
+ scalebox = getOption("xtable.scalebox", NULL),
+ comment = FALSE,
+ timestamp = NULL,
+ ...)
+{
+ class(x) <- c("xtableMatharray","data.frame")
+ print.xtable(x, floating = FALSE,
+ tabular.environment = 'array',
+ include.rownames = FALSE, include.colnames = FALSE,
+ hline.after = NULL,
+ print.results = print.results,
+ format.args = format.args,
+ scalebox = scalebox,
+ comment = comment,
+ timestamp = timestamp,
+ ...)
+}
### Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,\r
### MA 02111-1307, USA\r
\r
-## The generic for toLatex() is declared in the base package "utils"\r
+### The generic for toLatex() is declared in the base package "utils"\r
\r
toLatex.xtable <- function(object, ...){\r
- # Initially just capturing the output of print.xtable(). At some\r
- # point this could be refactored to have print.xtable() call\r
- # toLatex() instead. - CR, 30/01/2012\r
+ ## Initially just capturing the output of print.xtable(). At some\r
+ ## point this could be refactored to have print.xtable() call\r
+ ## toLatex() instead. - CR, 30/01/2012\r
dotArgs <- list(...)\r
dotArgs$x <- object\r
dotArgs$type <- "latex"\r
}
-## data.frame and matrix objects
+### data.frame and matrix objects
xtable.data.frame <- function(x, caption = NULL, label = NULL, align = NULL,
digits = NULL, display = NULL, auto = FALSE,
digits = NULL, display = NULL, auto = FALSE, ...) {
return(xtable.data.frame(data.frame(x, check.names = FALSE),
caption = caption, label = label, align = align,
- digits = digits, display = display, auto = auto))
+ digits = digits, display = display, auto = auto,
+ ...))
}
+### xtableMatharray object
+### To deal with numeric arrays such as a variance-covariance matrix
+### From a request by James Curran, 16 October 2015
+xtable.xtableMatharray <- function(x, caption = NULL, label = NULL,
+ align = NULL, digits = NULL,
+ display = NULL, auto = FALSE,
+ ...) {
+ class(x) <- c("xtableMatharray","matrix")
+ xtbl <- xtable.matrix(x,
+ caption = caption, label = label, align = align,
+ digits = digits, display = display, auto = auto,
+ ...)
+ class(xtbl) <- c("xtableMatharray","xtable","data.frame")
+ return(xtbl)
+}
### table objects (of 1 or 2 dimensions) by Guido Gay, 9 Feb 2007
### Fixed to pass R checks by DBD, 9 May 2007
}
-## anova objects
+### anova objects
xtable.anova <- function(x, caption = NULL, label = NULL, align = NULL,
digits = NULL, display = NULL, auto = FALSE, ...) {
}
-## aov objects
+### aov objects
xtable.aov <- function(x, caption = NULL, label = NULL, align = NULL,
digits = NULL, display = NULL, auto = FALSE, ...) {
-## lm objects
+### lm objects
xtable.lm <- function(x, caption = NULL, label = NULL, align = NULL,
digits = NULL, display = NULL, auto = FALSE, ...) {
}
-## glm objects
+### glm objects
xtable.glm <- function(x, caption = NULL, label = NULL, align = NULL,
digits = NULL, display = NULL, auto = FALSE, ...) {
}
-## prcomp objects
+### prcomp objects
xtable.prcomp <- function(x, caption = NULL, label = NULL, align = NULL,
digits = NULL, display = NULL, auto = FALSE, ...) {
tmp <- cbind(beta, exp(beta), se, beta/se, 1 - pchisq((beta/se)^2, 1))
dimnames(tmp) <- list(names(beta),
c("coef", "exp(coef)", "se(coef)", "z", "p"))
- }
- else {
+ } else {
tmp <- cbind( beta, exp(beta), se, beta/se,
signif(1 - pchisq((beta/se)^2, 1), digits - 1))
dimnames(tmp) <- list(names(beta),
"Arg8", "Arg9", "Arg10", "Arg11",
paste(tp.1, month.abb[tp.2], sep = " "))
tmp <- data.frame(x, row.names = ROWNAMES);
- }
- else if (inherits(x, "ts") && is.null(ncol(x))) {
+ } else if (inherits(x, "ts") && is.null(ncol(x))) {
COLNAMES <- switch(frequency(x),
"Value",
"Arg2", "Arg3", # Dummy arguments
--- /dev/null
+\name{print.xtableMatharray}\r
+\alias{print.xtableMatharray}\r
+\title{Print Math Array}\r
+\description{\r
+ For an object of class \code{"xtableMatharray"}, returns the LaTeX\r
+ commands to produce an array.\r
+}\r
+\usage{\r
+\method{print}{xtableMatharray}(x,\r
+ print.results = FALSE,\r
+ format.args = getOption("xtable.format.args", NULL),\r
+ scalebox = getOption("xtable.scalebox", NULL),\r
+ comment = FALSE,\r
+ timestamp = NULL,\r
+ ...)\r
+}\r
+\arguments{\r
+ \item{x}{An object of class \code{"xtableMatharray"}.}\r
+ \item{print.results}{If \code{TRUE}, the generated table is printed to\r
+ standard output. Set this to \code{FALSE} if you will just be using\r
+ the character vector that is returned invisibly.\r
+ Default value is \code{FALSE}.} \r
+ \item{format.args}{List of arguments for the \code{formatC} function.\r
+ For example, standard German number separators can be specified as\r
+ \code{format.args=list(big.mark = "'", decimal.mark = ",")}. The\r
+ arguments \code{digits} and \code{format} should not be included in\r
+ this list. See details for function \code{\link{print.xtable}}.\r
+ Default value is \code{NULL}.}\r
+ \item{scalebox}{If not \code{NULL}, a \code{scalebox} clause will be\r
+ added around the tabular environment with the specified value used\r
+ as the scaling factor.\r
+ Default value is \code{NULL}.}\r
+ \item{comment}{If \code{TRUE}, the version and timestamp comment is\r
+ included. Default value is \code{FALSE}. }\r
+ \item{timestamp}{Timestamp to include in LaTeX comment. Set this\r
+ to \code{NULL} to exclude the timestamp. Default value is \code{NULL}. }\r
+ \item{...}{Additional arguments. (Currently ignored.) }\r
+}\r
+\details{\r
+ Here are some details.\r
+}\r
+\value{\r
+ A character vector containing the LaTeX code for incorporating an\r
+ array in a mathematical expression.\r
+}\r
+\r
+\author{\r
+ David Scott \email{d.scott@auckland.ac.nz}.\r
+}\r
+\seealso{\r
+ \code{\link{print.xtable}}\r
+}\r
+\r
+\examples{\r
+V <- matrix(c(1.140380e-03, 3.010497e-05, 7.334879e-05,\r
+ 3.010497e-05, 3.320683e-04, -5.284854e-05,\r
+ 7.334879e-05, -5.284854e-05, 3.520928e-04), nrow = 3)\r
+V\r
+class(V) <- c("xtableMatharray")\r
+class(V)\r
+\r
+mth <- xtable(V)\r
+str(mth)\r
+mth\r
+}\r
+\r
+\keyword{print}\r
--- /dev/null
+require(xtable)
+V <- matrix(c(1.140380e-03, 3.010497e-05, 7.334879e-05,
+ 3.010497e-05, 3.320683e-04, -5.284854e-05,
+ 7.334879e-05, -5.284854e-05, 3.520928e-04), nrow = 3)
+V
+class(V) <- c("xtableMatharray")
+class(V)
+
+mth <- xtable(V)
+str(mth)
+mth
+
+tbl <- xtable(V, display = rep("E", 4))
+str(tbl)
+tbl
+
+V <- matrix(c(1.140380e-03, 3.010497e-05, 7.334879e-05,
+ 3.010497e-05, 3.320683e-04, -5.284854e-05,
+ 7.334879e-05, -5.284854e-05, 3.520928e-04), nrow = 3)
+V
+mth <- xtable(V, display = rep("E", 4))
+class(mth)
+mth
+class(mth) <- c("xtableMatharray")
+mth
+print(mth)
+print.xtableMatharray(xtable(V, display = rep("E", 4)))
+class(mth) <- c("xtableMatharray")
+mth
+
+V <- matrix(c(1.140380e-03, 3.010497e-05, 7.334879e-05,
+ 3.010497e-05, 3.320683e-04, -5.284854e-05,
+ 7.334879e-05, -5.284854e-05, 3.520928e-04), nrow = 3)
+V
+
+print.xtableMatharray(xtable(V),
+ format.args = list(display = rep("E", 4)))
+print.xtableMatharray(xtable(V),
+ format.args = list(digits = 6))
+
%**************************************************************************\r
\documentclass{article}\r
\usepackage[a4paper,height=24cm]{geometry} % geometry first\r
+\usepackage{listings}\r
\usepackage{array}\r
\usepackage{booktabs}\r
\usepackage{longtable}\r
\newcommand\code[1]{\texttt{#1}}\r
\newcommand\pkg[1]{\textbf{#1}}\r
\setcounter{tocdepth}{2}\r
+\r
+\lstset{language=R,basicstyle=\ttfamily,\r
+ keywordstyle=\ttfamily,\r
+ emphstyle=\itshape,\r
+ escapeinside = ||,\r
+ lineskip=0pt}\r
+\r
\begin{document}\r
\r
\title{The \pkg{xtable} Gallery}\r
temp.table\r
@\r
\r
+\subsection{Mathematical arrays}\r
+\label{sec:mathematical-arrays}\r
+\r
+Mathematical arrays (as compared to data arrays) can be printed\r
+correctly by declaring the class as \code{xtableMatharray}.\r
+<<matharraydata>>=\r
+V <- matrix(c(1.140380e-03, 3.010497e-05, 7.334879e-05,\r
+ 3.010497e-05, 3.320683e-04, -5.284854e-05,\r
+ 7.334879e-05, -5.284854e-05, 3.520928e-04), nrow = 3)\r
+V\r
+class(V) <- c("xtableMatharray")\r
+class(V)\r
+xtbl <- print(xtable(V, display = rep("E", 4)))\r
+@ %def\r
+\r
+Then \code{xtbl} can be used in an expression such as\r
+$V=\left[\Sexpr{xtbl}\right]$, produced by\r
+\begin{lstlisting}\r
+V=\left[\Sexp||r{xtbl}\right]. \r
+\end{lstlisting}\r
+\r
+\r
+An alternative display can be created using the \texttt{digits}\r
+argument. If \code{xtbl} is defined instead according to\r
+\r
+<<altmatharray, results = 'hide'>>=\r
+xtbl <- print(xtable(V, digits = 6))\r
+@ %def \r
+then we get\\\r
+$V=\left[\Sexpr{paste(print(xtable(V, digits = 6)))}\right].$ \r
\newpage\r
\r
<<include=FALSE>>=\r
function(str) gsub("_", "\\_", str, fixed = TRUE))\r
@\r
\r
+\r
\newpage\r
\r
\subsection{Markup in tables}\r
print(xtable(money), sanitize.rownames.function = function(x) {x})\r
@\r
\r
+\r
+\r
\section{Format examples}\r
\subsection{Adding a centering environment}\r
<<results='asis'>>=\r
tli.table\r
@\r
\r
+\subsection{Minus signs}\r
+\label{sec:minus-signs}\r
+\r
+The standard print functions do not render minus signs properly. They\r
+are actually hyphens (-) rather than minus signs ($-$). True minus\r
+signs can be obtained using the \code{math.style.negative} argument.\r
+\r
+\p\r
+Here is the \LaTeX{} which is produced:\r
+\r
+<<>>=\r
+pr1 <- prcomp(USArrests)\r
+print(xtable(pr1), math.style.negative = TRUE)\r
+@ \r
+\r
+And here is the resulting table.\r
+<<results='asis'>>=\r
+print(xtable(pr1), math.style.negative = TRUE)\r
+@\r
+\r
+\r
\newpage\r
\r
\subsection{Suppress row/column names}\r