Package: xtable
Version: 1.7-0
-Date: 2011/10/06
+Date: 2012/02/06
Title: Export tables to LaTeX or HTML
Author: David B. Dahl <dahl@stat.tamu.edu>
Maintainer: Charles Roosen <croosen@mango-solutions.com>
1.7-0 (NOT YET RELEASED)
* Added some vectorization code to improve performance.
+ * Let "caption" be length 2, in which case the second value is
+ the short caption used when creating a list of tables.
* Added "toLatex" method.
* Included "print.xtable" in the exported methods in the NAMESPACE file.
* Added "print.results" argument to "print" that can be used to
suppress the printing.
* Added "format.args" argument to "print" that can be used to
pass additional arguments such as "big.marks" to "formatC()".
- * Added "short.caption" argument to "print" to let the user
- specify a Latex short caption used when creating a list of tables.
- Conceptually this should really be an argument to "xtable()", but
- it was added to "print()" so authors of other packages don't need
- to change their "xtable" methods.
* Added "rotate.colnames" and "rotate.rownames" arguments to
"print.xtable".
* Added "booktabs" argument to use the "\toprule", "\midrule", and
html.table.attributes=getOption("xtable.html.table.attributes", "border=1"),\r
print.results=getOption("xtable.print.results", TRUE),\r
format.args=getOption("xtable.format.args", NULL),\r
- short.caption=getOption("xtable.short.caption", NULL),\r
rotate.rownames=getOption("xtable.rotate.rownames", FALSE),\r
rotate.colnames=getOption("xtable.rotate.colnames", FALSE),\r
booktabs = getOption("xtable.booktabs", FALSE),\r
...) {\r
+ # If caption is length 2, treat the second value as the "short caption"\r
+ caption <- attr(x,"caption",exact=TRUE)\r
+ short.caption <- NULL\r
+ if (!is.null(caption) && length(caption) > 1){\r
+ short.caption <- caption[2]\r
+ caption <- caption[1]\r
+ }\r
+ \r
# Claudio Agostinelli <claudio@unive.it> dated 2006-07-28 hline.after\r
# By default it print an \hline before and after the columns names independently they are printed or not and at the end of the table\r
# Old code that set hline.after should include c(-1, 0, nrow(x)) in the hline.after vector\r
BCAPTION <- paste("\\caption[", short.caption, "]{", sep="")\r
} \r
ECAPTION <- "} \\\\ \n"\r
- if ((!is.null(attr(x,"caption",exact=TRUE))) && (type=="latex")) BTABULAR <- paste(BTABULAR, BCAPTION, attr(x,"caption",exact=TRUE), ECAPTION, sep="")\r
+ if ((!is.null(caption)) && (type=="latex")) BTABULAR <- paste(BTABULAR, BCAPTION, caption, ECAPTION, sep="")\r
}\r
# Claudio Agostinelli <claudio@unive.it> dated 2006-07-28 add.to.row position -1\r
BTABULAR <- paste(BTABULAR,lastcol[1], sep="")\r
result <- result + BTABLE\r
result <- result + BENVIRONMENT\r
if ( floating == TRUE ) {\r
- if ((!is.null(attr(x,"caption",exact=TRUE))) && (type=="html" || caption.placement=="top")) result <- result + BCAPTION + attr(x,"caption",exact=TRUE) + ECAPTION\r
+ if ((!is.null(caption)) && (type=="html" || caption.placement=="top")) result <- result + BCAPTION + caption + ECAPTION\r
if (!is.null(attr(x,"label",exact=TRUE)) && (type=="latex" && caption.placement=="top")) result <- result + BLABEL + attr(x,"label",exact=TRUE) + ELABEL \r
}\r
result <- result + BSIZE\r
## fix 10-27-09 Liviu Andronic (landronimirc@gmail.com) the following 'if' condition is inserted in order to avoid\r
## that bottom caption interferes with a top caption of a longtable\r
if(caption.placement=="bottom"){\r
- if ((!is.null(attr(x,"caption",exact=TRUE))) && (type=="latex")) result <- result + BCAPTION + attr(x,"caption",exact=TRUE) + ECAPTION\r
+ if ((!is.null(caption)) && (type=="latex")) result <- result + BCAPTION + caption + ECAPTION\r
}\r
if (!is.null(attr(x,"label",exact=TRUE))) result <- result + BLABEL + attr(x,"label",exact=TRUE) + ELABEL\r
ETABULAR <- "\\end{longtable}\n"\r
result <- result + ETABULAR\r
result <- result + ESIZE\r
if ( floating == TRUE ) {\r
- if ((!is.null(attr(x,"caption",exact=TRUE))) && (type=="latex" && caption.placement=="bottom")) result <- result + BCAPTION + attr(x,"caption",exact=TRUE) + ECAPTION\r
+ if ((!is.null(caption)) && (type=="latex" && caption.placement=="bottom")) result <- result + BCAPTION + caption + ECAPTION\r
if (!is.null(attr(x,"label",exact=TRUE)) && caption.placement=="bottom") result <- result + BLABEL + attr(x,"label",exact=TRUE) + ELABEL \r
}\r
result <- result + EENVIRONMENT\r
"caption<-" <- function(x,value) UseMethod("caption<-")
"caption<-.xtable" <- function(x,value) {
- if (length(value)>1)
- stop("\"caption\" must have length 1")
+ if (length(value)>2)
+ stop("\"caption\" must have length 1 or 2")
attr(x,"caption") <- value
return(x)
}
html.table.attributes=getOption("xtable.html.table.attributes", "border=1"),\r
print.results=getOption("xtable.print.results", TRUE),\r
format.args=getOption("xtable.format.args", NULL),\r
- short.caption=getOption("xtable.short.caption", NULL),\r
rotate.rownames=getOption("xtable.rotate.rownames", FALSE),\r
rotate.colnames=getOption("xtable.rotate.colnames", FALSE),\r
booktabs = getOption("xtable.booktabs", FALSE),\r
\item{html.table.attributes}{In an HTML table, attributes associated with the \code{<TABLE>} tag. Default value is \code{border=1}.}\r
\item{print.results}{If \code{TRUE}, the generated table is printed to standard output. Set this to \code{FALSE} if you will just be using the character vector that is returned invisibly.}\r
\item{format.args}{List of arguments for the \code{formatC} function. For example, standard German number separators can be specified as \code{format.args=list(big.mark = "'", decimal.mark = ","))}.}\r
- \item{short.caption}{A "short caption" can be specified that gets used as the table descriptor when LaTeX generates a "List of Tables".}\r
\item{rotate.rownames}{If \code{TRUE}, the row names are displayed vertically in LaTeX.}\r
\item{rotate.colnames}{If \code{TRUE}, the column names are displayed vertically in LaTeX.}\r
\item{booktabs}{If \code{TRUE}, the \code{toprule}, \code{midrule} and \code{bottomrule} tags from the LaTex "booktabs" package are used rather than \code{hline} for the horizontal line tags.}\r
\arguments{
\item{x}{An R object of class found among \code{methods(xtable)}. See below on how to write additional method functions
for \code{xtable}.}
- \item{caption}{Character vector of length 1 containing the table's caption or title.
+ \item{caption}{Character vector of length 1 or 2 containing the table's caption or title. If length 2, the second item
+ is the "short caption" used when LaTeX generates a "List of Tables".
Set to \code{NULL} to suppress the caption. Default value is \code{NULL}.}
\item{label}{Character vector of length 1 containing the LaTeX label or HTML anchor.
Set to \code{NULL} to suppress the label. Default value is \code{NULL}.}
## Demonstration of additional formatC() arguments.
print(fm1.table, format.args=list(big.mark = "'", decimal.mark = ","))
-## Demonstration of short caption support.
+## Demonstration of "short caption" support.
fm1sc <- aov(tlimth ~ sex + ethnicty + grade, data=tli)
fm1sc.table <- xtable(fm1sc,
- caption="ANOVA Model with Predictors Sex, Ethnicity, and Grade")
-print(fm1sc.table,
- short.caption="ANOVA: Sex, Ethnicity, Grade")
+ caption=c("ANOVA Model with Predictors Sex, Ethnicity, and Grade",
+ "ANOVA: Sex, Ethnicity, Grade"))
+print(fm1sc.table)
## Demonstration of longtable support.
## Remember to insert \usepackage{longtable} on your LaTeX preamble