From 1f569e27e734124d45b040fde259f90011416f74 Mon Sep 17 00:00:00 2001 From: roosen Date: Sun, 24 Feb 2013 17:37:47 +0000 Subject: [PATCH] CR: Updates for next release git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@40 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- pkg/NEWS | 29 ++++++++----- pkg/R/print.xtable.R | 76 ++++++++++++++++++++-------------- pkg/R/table.attributes.R | 2 +- pkg/R/toLatex.R | 2 +- pkg/R/xtable.R | 2 +- pkg/inst/doc/xtableGallery.snw | 12 +++--- pkg/man/print.xtable.Rd | 18 +++++--- 7 files changed, 85 insertions(+), 56 deletions(-) diff --git a/pkg/NEWS b/pkg/NEWS index 10a193a..0a71015 100644 --- a/pkg/NEWS +++ b/pkg/NEWS @@ -1,14 +1,23 @@ -1.7-1 (NOT YET RELEASED) - * Fixed logicals bug (number 1911) +1.7-1 (2013-02-24) + * Fixed logicals bug (Req #1911) * Changed implementation of centering of tables. Instead of - inserting a centred environment, now a \centering command is - inserted. Response to request #2104. - * Implemented request #2168 which allows for margin tables as - possible with document class tufte-handout. An example of usage is - found in the vignette produced by margintable.Rnw which is in - inst/doc. - -1.7-0 + inserting a centered environment, now a \centering command is + inserted. (Req #2104) + * Allow for margin tables as possible with document class + tufte-handout. An example of usage is found in the vignette + produced by margintable.Rnw which is in inst/doc. (Req #2168) + * Added "timestamp" argument to print.xtable(). Set it to NULL + if no timestamp is desired. (Req #2246) + * Added "comment" argument to print.xtable(). Set it to FALSE + to exclude the version and timestamp comment. (Req #2246) + * Added "caption.width" argument. If not NULL then the caption + is placed in a "parbox" of the specified width. (Req #2247) + * Remove the check on whether the "floating.environment" is + in a list of known floating environments. Users want to use + floating environments from multiple options LaTeX + packages (Req #2488, #2578) + +1.7-0 (2012-02-10) * 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. diff --git a/pkg/R/print.xtable.R b/pkg/R/print.xtable.R index c0cce93..0060222 100644 --- a/pkg/R/print.xtable.R +++ b/pkg/R/print.xtable.R @@ -2,7 +2,7 @@ ### ### Produce LaTeX and HTML tables from R objects. ### -### Copyright 2000-2012 David B. Dahl +### Copyright 2000-2013 David B. Dahl ### ### Maintained by Charles Roosen ### @@ -29,6 +29,7 @@ print.xtable <- function(x, floating.environment = getOption("xtable.floating.environment", "table"), table.placement = getOption("xtable.table.placement", "ht"), caption.placement = getOption("xtable.caption.placement", "bottom"), + caption.width = getOption("xtable.caption.width", NULL), latex.environments = getOption("xtable.latex.environments", c("center")), tabular.environment = getOption("xtable.tabular.environment", "tabular"), size = getOption("xtable.size", NULL), @@ -52,7 +53,8 @@ print.xtable <- function(x, booktabs = getOption("xtable.booktabs", FALSE), scalebox = getOption("xtable.scalebox", NULL), width = getOption("xtable.width", NULL), - timestamp = date(), + comment = getOption("xtable.comment", TRUE), + timestamp = getOption("xtable.timestamp", date()), ...) { ## If caption is length 2, treat the second value as the "short caption" @@ -121,11 +123,11 @@ print.xtable <- function(x, ## Original code before changes in version 1.6-1 ## PHEADER <- "\\hline\n" - ## booktabs code from Matthieu Stigler , + ## booktabs code from Matthieu Stigler , ## 1 Feb 2012 if(!booktabs){ PHEADER <- "\\hline\n" - } else { + } else { PHEADER <- ifelse(-1%in%hline.after, "\\toprule\n", "") if(0%in%hline.after) { PHEADER <- c(PHEADER, "\\midrule\n") @@ -142,13 +144,13 @@ print.xtable <- function(x, if (!is.null(hline.after)) { ## booktabs change - Matthieu Stigler: fill the hline arguments ## separately, 1 Feb 2012 - ## + ## ## Code before booktabs change was: - ## add.to.row$pos[[npos+1]] <- hline.after + ## add.to.row$pos[[npos+1]] <- hline.after if (!booktabs){ add.to.row$pos[[npos+1]] <- hline.after - } else { + } else { for(i in 1:length(hline.after)) { add.to.row$pos[[npos+i]] <- hline.after[i] } @@ -165,7 +167,7 @@ print.xtable <- function(x, lastcol[addpos[j]+2] <- paste(lastcol[addpos[j]+2], paste(rep(add.to.row$command[i], freq[j]), - sep = "", collapse = ""), + sep = "", collapse = ""), sep = " ") } } @@ -176,11 +178,13 @@ print.xtable <- function(x, if (!all(!is.na(match(type, c("latex","html"))))) { stop("\"type\" must be in {\"latex\", \"html\"}") } - if (!all(!is.na(match(floating.environment, - c("table","table*","sidewaystable", - "margintable"))))) { - stop("\"type\" must be in {\"table\", \"table*\", \"sidewaystable\", \"margintable\"}") - } + ## Disabling the check on known floating environments as many users + ## want to use additional environments. + # if (!all(!is.na(match(floating.environment, + # c("table","table*","sidewaystable", + # "margintable"))))) { + # stop("\"type\" must be in {\"table\", \"table*\", \"sidewaystable\", \"margintable\"}") + # } if (("margintable" %in% floating.environment) & (!is.null(table.placement))) { warning("margintable does not allow for table placement; setting table.placement to NULL") @@ -256,17 +260,17 @@ print.xtable <- function(x, tmp.index.start <- tmp.index.start + 1 tmp.index.start <- tmp.index.start + 1 } - ## Added "width" argument for use with "tabular*" or + ## Added "width" argument for use with "tabular*" or ## "tabularx" environments - CR, 7/2/12 - if (is.null(width)){ + if (is.null(width)){ WIDTH <-"" - } else if (is.element(tabular.environment, + } else if (is.element(tabular.environment, c("tabular", "longtable"))){ warning("Ignoring 'width' argument. The 'tabular' and 'longtable' environments do not support a width specification. Use another environment such as 'tabular*' or 'tabularx' to specify the width.") WIDTH <- "" - } else { + } else { WIDTH <- paste("{", width, "}", sep = "") - } + } BTABULAR <- paste("\\begin{", tabular.environment, "}", @@ -300,12 +304,12 @@ print.xtable <- function(x, ## the \hline at the end, if present, is set in full matrix ETABULAR <- paste("\\end{", tabular.environment, "}\n", sep = "") - ## Add scalebox - CR, 7/2/12 - if (!is.null(scalebox)){ + ## Add scalebox - CR, 7/2/12 + if (!is.null(scalebox)){ BTABULAR <- paste("\\scalebox{", scalebox, "}{\n", BTABULAR, sep = "") ETABULAR <- paste(ETABULAR, "}\n", sep = "") - } + } ## BSIZE contributed by Benno in e-mail ## dated Wednesday, December 01, 2004 @@ -320,13 +324,21 @@ print.xtable <- function(x, ESIZE <- "}\n" } BLABEL <- "\\label{" - ELABEL <- "}\n" - if (is.null(short.caption)){ - BCAPTION <- "\\caption{" - } else { - BCAPTION <- paste("\\caption[", short.caption, "]{", sep = "") - } - ECAPTION <- "}\n" + ELABEL <- "}\n" + ## Added caption width (jeff.laake@nooa.gov) + if(!is.null(caption.width)){ + BCAPTION <- paste("\\parbox{",caption.width,"}{",sep="") + ECAPTION <- "}" + } else { + BCAPTION <- NULL + ECAPTION <- NULL + } + if (is.null(short.caption)){ + BCAPTION <- paste(BCAPTION,"\\caption{",sep="") + } else { + BCAPTION <- paste(BCAPTION,"\\caption[", short.caption, "]{", sep="") + } + ECAPTION <- paste(ECAPTION,"} \n",sep="") BROW <- "" EROW <- " \\\\ \n" BTH <- "" @@ -436,12 +448,14 @@ print.xtable <- function(x, info <- R.Version() ## modified Claudio Agostinelli dated 2006-07-28 ## to set automatically the package version - result <- result + BCOMMENT + type + " table generated in " + + if (comment){ + result <- result + BCOMMENT + type + " table generated in " + info$language + " " + info$major + "." + info$minor + " by xtable " + packageDescription('xtable')$Version + " package" + ECOMMENT - if (!is.null(timestamp)){ - result <- result + BCOMMENT + timestamp + ECOMMENT + if (!is.null(timestamp)){ + result <- result + BCOMMENT + timestamp + ECOMMENT + } } ## Claudio Agostinelli dated 2006-07-28 only.contents if (!only.contents) { diff --git a/pkg/R/table.attributes.R b/pkg/R/table.attributes.R index b228f68..ed3f9c0 100644 --- a/pkg/R/table.attributes.R +++ b/pkg/R/table.attributes.R @@ -2,7 +2,7 @@ ### ### Produce LaTeX and HTML tables from R objects. ### -### Copyright 2000-2007 David B. Dahl +### Copyright 2000-2013 David B. Dahl ### ### This file is part of the `xtable' library for R and related languages. ### It is made available under the terms of the GNU General Public diff --git a/pkg/R/toLatex.R b/pkg/R/toLatex.R index ceb8320..a67934d 100644 --- a/pkg/R/toLatex.R +++ b/pkg/R/toLatex.R @@ -2,7 +2,7 @@ ### ### Produce LaTeX and HTML tables from R objects. ### -### Copyright 2000-2012 David B. Dahl +### Copyright 2000-2013 David B. Dahl ### ### Maintained by Charles Roosen ### diff --git a/pkg/R/xtable.R b/pkg/R/xtable.R index 6c65954..47af4d4 100644 --- a/pkg/R/xtable.R +++ b/pkg/R/xtable.R @@ -2,7 +2,7 @@ ### ### Produce LaTeX and HTML tables from R objects. ### -### Copyright 2000-2007 David B. Dahl +### Copyright 2000-2013 David B. Dahl ### ### This file is part of the `xtable' library for R and related languages. ### It is made available under the terms of the GNU General Public diff --git a/pkg/inst/doc/xtableGallery.snw b/pkg/inst/doc/xtableGallery.snw index 4922c51..3994324 100644 --- a/pkg/inst/doc/xtableGallery.snw +++ b/pkg/inst/doc/xtableGallery.snw @@ -244,9 +244,9 @@ temp.ts <- ts(cumsum(1+round(rnorm(100), 0)), start = c(1954, 7), frequency=12) if (FALSE) { for(i in c("latex","html")) { outFileName <- paste("xtable.",ifelse(i=="latex","tex",i),sep="") - print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environment=NULL) - print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environment="") - print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environment="center") + print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environments=NULL) + print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environments="") + print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environments="center") print(xtable(anova(glm.D93,test="Chisq")),type=i,file=outFileName,append=TRUE) print(xtable(anova(glm.D93)),hline.after=c(1),size="small",type=i,file=outFileName,append=TRUE) # print(xtable(pr2),type=i,file=outFileName,append=TRUE) @@ -298,9 +298,9 @@ print(xtable(money),sanitize.rownames.function=function(x) {x}) \section{Format examples} \subsection{Adding a centering environment } <>= - print(xtable(lm.D9,caption="\\tt latex.environment=NULL"),latex.environment=NULL) - print(xtable(lm.D9,caption="\\tt latex.environment=\"\""),latex.environment="") - print(xtable(lm.D9,caption="\\tt latex.environment=\"center\""),latex.environment="center") + print(xtable(lm.D9,caption="\\tt latex.environments=NULL"),latex.environments=NULL) + print(xtable(lm.D9,caption="\\tt latex.environments=\"\""),latex.environments="") + print(xtable(lm.D9,caption="\\tt latex.environments=\"center\""),latex.environments="center") @ \subsection{Column alignment} diff --git a/pkg/man/print.xtable.Rd b/pkg/man/print.xtable.Rd index 879543b..efb537f 100644 --- a/pkg/man/print.xtable.Rd +++ b/pkg/man/print.xtable.Rd @@ -14,6 +14,7 @@ floating.environment = getOption("xtable.floating.environment", "table"), table.placement = getOption("xtable.table.placement", "ht"), caption.placement = getOption("xtable.caption.placement", "bottom"), + caption.width = getOption("xtable.caption.width", NULL), latex.environments = getOption("xtable.latex.environments", c("center")), tabular.environment = getOption("xtable.tabular.environment", "tabular"), size = getOption("xtable.size", NULL), @@ -38,7 +39,8 @@ booktabs = getOption("xtable.booktabs", FALSE), scalebox = getOption("xtable.scalebox", NULL), width = getOption("xtable.width", NULL), - timestamp = date(), + comment = getOption("xtable.comment", TRUE), + timestamp = getOption("xtable.timestamp", date()), ...)} \arguments{ \item{x}{An object of class \code{"xtable"}.} @@ -60,9 +62,8 @@ Default value is \code{TRUE}. } \item{floating.environment}{If \code{floating=TRUE} and \code{type="latex"}, the resulting table uses the specified floating - environment. Possible values are \code{"table"}, \code{"table*"}, or - \code{"sidewaystable"} (defined in the LaTeX package - 'rotating'). + environment. Possible values include \code{"table"}, \code{"table*"}, + and other floating environments defined in LaTeX packages. Default value is \code{"table"}.} \item{table.placement}{If \code{floating=TRUE} and \code{type="latex"}, the floating table will have placement given by @@ -74,6 +75,9 @@ of the table if \code{caption.placement} is \code{"bottom"} and at the top of the table if it equals \code{"top"}. Default value is \code{"bottom"}.} + \item{caption.width}{The caption will be placed in a \code{"parbox"} + of the specified width if \code{caption.width} is not \code{NULL} and + \code{type="latex"}. Default value is \code{NULL}.} \item{latex.environments}{If \code{floating=TRUE} and \code{type="latex"}, the specificed latex environments (provided as a character vector) will enclose the tabular environment. @@ -158,9 +162,11 @@ width when using tabular environments such as \code{tabular*} and \code{tabularx}. Note that table width specification is not supported with the \code{tabular} or \code{longtable} environments. } + \item{comment}{If \code{TRUE}, the version and timestamp comment is + included. Default value is \code{TRUE}. } \item{timestamp}{Timestamp to include in LaTeX comment. Set this - to \code{NULL} to exclude the timestamp.} - \item{...}{Additional arguments. (Currently ignored.)} + to \code{NULL} to exclude the timestamp. Default value is \code{date()}. } + \item{...}{Additional arguments. (Currently ignored.) } } \details{ This function displays or writes to disk the code to produce a table -- 2.39.2