From: roosen Date: Mon, 6 Feb 2012 15:27:05 +0000 (+0000) Subject: Removed the "short.caption" argument. Instead, "caption" can be length 2 in which... X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=22a6b6929c607f5505c05931c5473c841fa8868a;p=xtable.git Removed the "short.caption" argument. Instead, "caption" can be length 2 in which case the second item is used as the short caption. git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@27 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- diff --git a/pkg/DESCRIPTION b/pkg/DESCRIPTION index d3bfaed..58971d8 100644 --- a/pkg/DESCRIPTION +++ b/pkg/DESCRIPTION @@ -1,6 +1,6 @@ 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 Maintainer: Charles Roosen diff --git a/pkg/NEWS b/pkg/NEWS index 4e41217..48e7441 100644 --- a/pkg/NEWS +++ b/pkg/NEWS @@ -1,16 +1,13 @@ 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 diff --git a/pkg/R/print.xtable.R b/pkg/R/print.xtable.R index 282e2a2..bae66a1 100644 --- a/pkg/R/print.xtable.R +++ b/pkg/R/print.xtable.R @@ -48,11 +48,18 @@ print.xtable <- function( html.table.attributes=getOption("xtable.html.table.attributes", "border=1"), print.results=getOption("xtable.print.results", TRUE), format.args=getOption("xtable.format.args", NULL), - short.caption=getOption("xtable.short.caption", NULL), rotate.rownames=getOption("xtable.rotate.rownames", FALSE), rotate.colnames=getOption("xtable.rotate.colnames", FALSE), booktabs = getOption("xtable.booktabs", FALSE), ...) { + # If caption is length 2, treat the second value as the "short caption" + caption <- attr(x,"caption",exact=TRUE) + short.caption <- NULL + if (!is.null(caption) && length(caption) > 1){ + short.caption <- caption[2] + caption <- caption[1] + } + # Claudio Agostinelli dated 2006-07-28 hline.after # 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 # Old code that set hline.after should include c(-1, 0, nrow(x)) in the hline.after vector @@ -209,7 +216,7 @@ print.xtable <- function( BCAPTION <- paste("\\caption[", short.caption, "]{", sep="") } ECAPTION <- "} \\\\ \n" - if ((!is.null(attr(x,"caption",exact=TRUE))) && (type=="latex")) BTABULAR <- paste(BTABULAR, BCAPTION, attr(x,"caption",exact=TRUE), ECAPTION, sep="") + if ((!is.null(caption)) && (type=="latex")) BTABULAR <- paste(BTABULAR, BCAPTION, caption, ECAPTION, sep="") } # Claudio Agostinelli dated 2006-07-28 add.to.row position -1 BTABULAR <- paste(BTABULAR,lastcol[1], sep="") @@ -341,7 +348,7 @@ print.xtable <- function( result <- result + BTABLE result <- result + BENVIRONMENT if ( floating == TRUE ) { - if ((!is.null(attr(x,"caption",exact=TRUE))) && (type=="html" || caption.placement=="top")) result <- result + BCAPTION + attr(x,"caption",exact=TRUE) + ECAPTION + if ((!is.null(caption)) && (type=="html" || caption.placement=="top")) result <- result + BCAPTION + caption + ECAPTION if (!is.null(attr(x,"label",exact=TRUE)) && (type=="latex" && caption.placement=="top")) result <- result + BLABEL + attr(x,"label",exact=TRUE) + ELABEL } result <- result + BSIZE @@ -477,7 +484,7 @@ print.xtable <- function( ## fix 10-27-09 Liviu Andronic (landronimirc@gmail.com) the following 'if' condition is inserted in order to avoid ## that bottom caption interferes with a top caption of a longtable if(caption.placement=="bottom"){ - if ((!is.null(attr(x,"caption",exact=TRUE))) && (type=="latex")) result <- result + BCAPTION + attr(x,"caption",exact=TRUE) + ECAPTION + if ((!is.null(caption)) && (type=="latex")) result <- result + BCAPTION + caption + ECAPTION } if (!is.null(attr(x,"label",exact=TRUE))) result <- result + BLABEL + attr(x,"label",exact=TRUE) + ELABEL ETABULAR <- "\\end{longtable}\n" @@ -485,7 +492,7 @@ print.xtable <- function( result <- result + ETABULAR result <- result + ESIZE if ( floating == TRUE ) { - if ((!is.null(attr(x,"caption",exact=TRUE))) && (type=="latex" && caption.placement=="bottom")) result <- result + BCAPTION + attr(x,"caption",exact=TRUE) + ECAPTION + if ((!is.null(caption)) && (type=="latex" && caption.placement=="bottom")) result <- result + BCAPTION + caption + ECAPTION if (!is.null(attr(x,"label",exact=TRUE)) && caption.placement=="bottom") result <- result + BLABEL + attr(x,"label",exact=TRUE) + ELABEL } result <- result + EENVIRONMENT diff --git a/pkg/R/table.attributes.R b/pkg/R/table.attributes.R index f2a08c7..ca09e98 100644 --- a/pkg/R/table.attributes.R +++ b/pkg/R/table.attributes.R @@ -22,8 +22,8 @@ "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) } diff --git a/pkg/man/print.xtable.Rd b/pkg/man/print.xtable.Rd index 62d05b1..03faef6 100644 --- a/pkg/man/print.xtable.Rd +++ b/pkg/man/print.xtable.Rd @@ -29,7 +29,6 @@ html.table.attributes=getOption("xtable.html.table.attributes", "border=1"), print.results=getOption("xtable.print.results", TRUE), format.args=getOption("xtable.format.args", NULL), - short.caption=getOption("xtable.short.caption", NULL), rotate.rownames=getOption("xtable.rotate.rownames", FALSE), rotate.colnames=getOption("xtable.rotate.colnames", FALSE), booktabs = getOption("xtable.booktabs", FALSE), @@ -68,7 +67,6 @@ \item{html.table.attributes}{In an HTML table, attributes associated with the \code{} tag. Default value is \code{border=1}.} \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.} \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 = ","))}.} - \item{short.caption}{A "short caption" can be specified that gets used as the table descriptor when LaTeX generates a "List of Tables".} \item{rotate.rownames}{If \code{TRUE}, the row names are displayed vertically in LaTeX.} \item{rotate.colnames}{If \code{TRUE}, the column names are displayed vertically in LaTeX.} \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.} diff --git a/pkg/man/xtable.Rd b/pkg/man/xtable.Rd index 41628ac..b8a7f99 100644 --- a/pkg/man/xtable.Rd +++ b/pkg/man/xtable.Rd @@ -26,7 +26,8 @@ xtable(x, caption=NULL, label=NULL, align=NULL, digits=NULL, \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}.} @@ -196,12 +197,12 @@ print(xtable(anova(glm.D93)),hline.after=c(1),size="small") ## 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