]> git.donarmstrong.com Git - xtable.git/commitdiff
Submitting multiple changes as R-Forge SVN has been down. Added the use of getOption...
authorroosen <roosen@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Thu, 2 Feb 2012 08:34:09 +0000 (08:34 +0000)
committerroosen <roosen@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Thu, 2 Feb 2012 08:34:09 +0000 (08:34 +0000)
git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@26 edb9625f-4e0d-4859-8d74-9fd3b1da38cb

pkg/DESCRIPTION
pkg/NEWS
pkg/R/print.xtable.R
pkg/inst/doc/xtableGallery.snw
pkg/man/print.xtable.Rd
pkg/man/xtable.Rd

index 4c8eab308cf8b0efdf7f33fa13bd43de1a10fcb2..d3bfaedb6f8faadf1235f64b7b363a341ca63412 100644 (file)
@@ -1,5 +1,5 @@
 Package: xtable
-Version: 1.6-1
+Version: 1.7-0
 Date: 2011/10/06
 Title: Export tables to LaTeX or HTML
 Author: David B. Dahl <dahl@stat.tamu.edu>
index 78eefef3eb78b10cd63a8fc39e11df419e24c670..4e41217fc628caf3231a965e7b5666b15405800e 100644 (file)
--- a/pkg/NEWS
+++ b/pkg/NEWS
@@ -1,20 +1,29 @@
-1.6-1 (NOT YET RELEASED)
+1.7-0 (NOT YET RELEASED)
   * Added some vectorization code to improve performance.
   * 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. 
+    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  
+    "\bottomrule" tags from the Latex "booktabs" package rather than
+       using "\hline" for all horizontal lines.
+  * Changed the "print.xtable()" arguments to use "getOption()"
+    to check the options for a default value.  This was suggested
+       since "print.xtable()" has a lot of arguments that the user
+       will typically leave unchanged between tables.
   * Added an "is.null()" check on the "table.placement" argument.
-  * Put in some changes from John Leonard regarding the placement
-    of newlines when "longtable" and "add.to.row" are used together.
-  * Included "print.xtable" in the exported methods in the NAMESPACE file.
   * Added an example of header and footer specification with longtable
     to the vignette.  
+  * Added examples using the new arguments to the vignette.
        
 1.6-0 (2011-10-07)
   * Allow "table*" as a value for "floating.environment" in print.xtable().
index 2c1c5dc25440a9db8a67a2b54f18a6735a8ecf68..282e2a2e7dcf94eda26962690879d7dba17e704e 100644 (file)
 ### MA 02111-1307, USA\r
 print.xtable <- function(\r
   x,\r
-  type="latex",\r
-  file="",\r
-  append=FALSE,\r
-  floating=TRUE,\r
-  floating.environment="table",\r
-  table.placement="ht",\r
-  caption.placement="bottom",\r
-  latex.environments=c("center"),\r
-  tabular.environment="tabular",\r
-  size=NULL,\r
-  hline.after=c(-1,0,nrow(x)),\r
-  NA.string="",\r
-  include.rownames=TRUE,\r
-  include.colnames=TRUE,\r
-  only.contents=FALSE,\r
-  add.to.row=NULL,\r
-  sanitize.text.function=NULL,\r
-  sanitize.rownames.function=sanitize.text.function,\r
-  sanitize.colnames.function=sanitize.text.function,\r
-  math.style.negative=FALSE,\r
-  html.table.attributes="border=1",\r
-  print.results=TRUE,\r
-  format.args=NULL,\r
-  short.caption=NULL,\r
-  rotate.rownames=FALSE,\r
-  rotate.colnames=FALSE,\r
+  type=getOption("xtable.type", "latex"),\r
+  file=getOption("xtable.file", ""),\r
+  append=getOption("xtable.append", FALSE),\r
+  floating=getOption("xtable.floating", TRUE),\r
+  floating.environment=getOption("xtable.floating.environment", "table"),\r
+  table.placement=getOption("xtable.table.placement", "ht"),\r
+  caption.placement=getOption("xtable.caption.placement", "bottom"),\r
+  latex.environments=getOption("xtable.latex.environments", c("center")),\r
+  tabular.environment=getOption("xtable.tabular.environment", "tabular"),\r
+  size=getOption("xtable.size", NULL),\r
+  hline.after=getOption("xtable.hline.after", c(-1,0,nrow(x))),\r
+  NA.string=getOption("xtable.NA.string", ""),\r
+  include.rownames=getOption("xtable.include.rownames", TRUE),\r
+  include.colnames=getOption("xtable.include.colnames", TRUE),\r
+  only.contents=getOption("xtable.only.contents", FALSE),\r
+  add.to.row=getOption("xtable.add.to.row", NULL),\r
+  sanitize.text.function=getOption("xtable.sanitize.text.function", NULL),\r
+  sanitize.rownames.function=getOption("xtable.sanitize.rownames.function", \r
+    sanitize.text.function),\r
+  sanitize.colnames.function=getOption("xtable.sanitize.colnames.function", \r
+    sanitize.text.function),\r
+  math.style.negative=getOption("xtable.math.style.negative", FALSE),\r
+  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
   # 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
@@ -94,21 +97,42 @@ print.xtable <- function(
   # Claudio Agostinelli <claudio@unive.it> dated 2006-07-28 add.to.row\r
   # Add further commands at the end of rows\r
   if (type=="latex") {\r
-     PHEADER <- "\\hline\n"\r
-        # John Leonard <jleonard99@gmail.com> October 21, 2011\r
-        # The extra \hline gets in the way when using longtable and add.to.row\r
-        if(tabular.environment=="longtable" && !is.null(add.to.row) ) {\r
-          PHEADER <- ""\r
-     }    \r
+    ## Original code before changes in version 1.6-1\r
+    # PHEADER <- "\\hline\n"\r
+\r
+       # booktabs code from Matthieu Stigler <matthieu.stigler@gmail.com>, 1 Feb 2012\r
+    if(!booktabs){\r
+      PHEADER <- "\\hline\n"\r
+       } else {\r
+      PHEADER <- ifelse(-1%in%hline.after, "\\toprule\n", "") \r
+      if(0%in%hline.after) {\r
+        PHEADER <- c(PHEADER, "\\midrule\n")\r
+         }\r
+      if(nrow(x)%in%hline.after) {\r
+        PHEADER <- c(PHEADER, "\\bottomrule\n")\r
+         }\r
+    }\r
   } else {\r
      PHEADER <- ""\r
   }\r
    \r
   lastcol <- rep(" ", nrow(x)+2)\r
   if (!is.null(hline.after)) {\r
-     add.to.row$pos[[npos+1]] <- hline.after\r
-     add.to.row$command <- c(add.to.row$command, PHEADER)\r
+    # booktabs change - Matthieu Stigler: fill the hline arguments separately, 1 Feb 2012\r
+       #\r
+    # Code before booktabs change was:\r
+       #    add.to.row$pos[[npos+1]] <- hline.after\r
+\r
+    if (!booktabs){\r
+       add.to.row$pos[[npos+1]] <- hline.after\r
+       } else {\r
+       for(i in 1:length(hline.after)) {           \r
+             add.to.row$pos[[npos+i]] <- hline.after[i] \r
+          }\r
+    }     \r
+    add.to.row$command <- c(add.to.row$command, PHEADER)\r
   }\r
+\r
   if ( length(add.to.row$command) > 0 ) {\r
     for (i in 1:length(add.to.row$command)) {\r
       addpos <- add.to.row$pos[[i]]\r
@@ -440,19 +464,16 @@ print.xtable <- function(
   full[,multiplier*(0:(ncol(x)+pos-1))+6] <- ETD\r
 \r
   full[,multiplier*(ncol(x)+pos)+2] <- paste(EROW, lastcol[-(1:2)], sep=" ")\r
-  \r
-  # John Leonard <jleonard99@gmail.com> October 21, 2011\r
-  # Removes the "\\" from the last row of the contents so that \r
-  # booktabs (\bottomline) appears in the correct position.\r
-  if(tabular.environment=="longtable" & !is.null(add.to.row)) {\r
-    full[dim(full)[1],multiplier*(ncol(x)+pos)+2] <- "%\n" \r
-  }\r
-  \r
\r
   if (type=="latex") full[,2] <- ""\r
   result <- result + lastcol[2] + paste(t(full),collapse="")\r
   if (!only.contents) {\r
     if (tabular.environment == "longtable") {\r
-      result <- result + PHEADER\r
+         # booktabs change added the if() - 1 Feb 2012\r
+         if(!booktabs) {\r
+           result <- result + PHEADER\r
+      }\r
+         \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
@@ -471,6 +492,7 @@ print.xtable <- function(
     result <- result + ETABLE\r
   }   \r
   result <- sanitize.final(result)\r
+  \r
   if (print.results){\r
        print(result)\r
   }\r
index 79d1626e6f43c9680a323d11705e8216391e2a56..da839116f7ab2ee00bae3bd762e725475d42e3dc 100644 (file)
@@ -31,6 +31,7 @@ The xtable gallery
 \SweaveOpts{prefix.string=figdir/fig,debug=TRUE,eps=FALSE,echo=TRUE}
 \usepackage{rotating} 
 \usepackage{longtable} 
+\usepackage{booktabs}
 %\usepackage{hyperref}
 \begin{document}
 
@@ -397,10 +398,30 @@ print((tli.table),rotate.rownames=TRUE,rotate.colnames=TRUE)
 @
 
 \subsection{Horizontal lines}
+
+\subsubsection{Line locations}
+
+Use the {\tt hline.after} argument to specify the position of the horizontal lines.
+
 <<results=tex>>=
 print(xtable(anova(glm.D93)),hline.after=c(1),floating=FALSE)
 @
 
+\subsubsection{Line styles}
+
+The \LaTeX package {\tt booktabs} can be used to specify different 
+line style tags for top, middle, and bottom lines.  Specifying
+{\tt booktabs = TRUE} will lead to separate tags being generated
+for the three line types.
+
+Insert \verb|\usepackage{booktabs}| in your \LaTeX preamble and
+define the {\tt toprule}, {\tt midrule}, and {\tt bottomrule}
+tags to specify the line styles.
+
+<<results=tex>>=
+print(tli.table , booktabs=TRUE)
+@
+
 \subsection{Table-level \LaTeX}
 <<results=tex>>=
 print(xtable(anova(glm.D93)),size="small",floating=FALSE)
@@ -408,7 +429,7 @@ print(xtable(anova(glm.D93)),size="small",floating=FALSE)
 
 
 \subsection{Long tables}
-Remember to insert \verb|\usepackage{longtable}| in your LaTeX preamble.
+Remember to insert \verb|\usepackage{longtable}| in your \LaTeX preamble.
 See Table \ref{tabbig}.
 
 <<longtable>>=
@@ -422,11 +443,11 @@ x.big <- xtable(x,label='tabbig',
 print(x.big,tabular.environment='longtable',floating=FALSE)
 @
 
-\subsubsection{Long tables with headers on each page}
+\subsubsection{Long tables with the header on each page}
 
 The {\tt add.to.row} argument can be used to display the header 
 for a long table on each page, and to add a "continued" footer
-on all pages except the last page.
+on all pages except the last page.  See Table \ref{tabbig2}.
 
 <<results=tex>>=
 library(xtable)
@@ -442,9 +463,9 @@ addtorow$command<-c(paste(
     "  {\\footnotesize Continued on next page} \n",
     "  \\endfoot \n",
     "  \\endlastfoot \n",sep=""))
-x.big <- xtable(x, label = "tabbig", 
-    caption = "Example of longtable spanning several pages")
-print(x.big, tabular.environment = "longtable", floating = FALSE,
+x.big2 <- xtable(x, label = "tabbig2", 
+    caption = "Example of longtable with the header on each page")
+print(x.big2, tabular.environment = "longtable", floating = FALSE,
 include.rownames=FALSE,add.to.row=addtorow,hline.after=c(-1) )
 @
 
@@ -470,11 +491,7 @@ output and also return the character strings invisibly.  The printing to
 standard output can be suppressed by specifying {\tt print.results = FALSE}.
 
 <<>>=
-# This will print the output and store it.
-x.out <- print(tli.table)
-
-# This will just store the value.
-x.out2 <- print(tli.table, print.results = FALSE)
+x.out <- print(tli.table, print.results = FALSE)
 @
 
 Formatted output can also be captured without printing with the
index 8c75a2541fb9959b6259527ac48c7647ab38a03d..62d05b13a05e3185c252b7016c8fce637db468c0 100644 (file)
@@ -3,24 +3,37 @@
 \title{Print Export Tables}\r
 \description{Function returning and displaying or writing to disk the LaTeX or HTML code associated with the supplied object of class \code{xtable}.}\r
 \usage{\r
-       \method{print}{xtable}(x, type="latex", file="", append=FALSE, \r
-    floating=TRUE, floating.environment="table", \r
-    table.placement = "ht", caption.placement="bottom", \r
-               latex.environments=c("center"),\r
-    tabular.environment = "tabular", size=NULL,\r
-               hline.after=c(-1,0,nrow(x)), NA.string = "", include.rownames=TRUE, \r
-               include.colnames=TRUE, only.contents=FALSE, add.to.row=NULL, \r
-               sanitize.text.function=NULL, \r
-    sanitize.rownames.function=sanitize.text.function,\r
-               sanitize.colnames.function=sanitize.text.function, \r
-    math.style.negative=FALSE, \r
-               html.table.attributes="border=1", \r
-               print.results=TRUE, \r
-    format.args=NULL, \r
-               short.caption=NULL, \r
-               rotate.rownames = FALSE,\r
-               rotate.colnames = FALSE,\r
-               ...)}\r
+\method{print}{xtable}(x, \r
+  type=getOption("xtable.type", "latex"),\r
+  file=getOption("xtable.file", ""),\r
+  append=getOption("xtable.append", FALSE),\r
+  floating=getOption("xtable.floating", TRUE),\r
+  floating.environment=getOption("xtable.floating.environment", "table"),\r
+  table.placement=getOption("xtable.table.placement", "ht"),\r
+  caption.placement=getOption("xtable.caption.placement", "bottom"),\r
+  latex.environments=getOption("xtable.latex.environments", c("center")),\r
+  tabular.environment=getOption("xtable.tabular.environment", "tabular"),\r
+  size=getOption("xtable.size", NULL),\r
+  hline.after=getOption("xtable.hline.after", c(-1,0,nrow(x))),\r
+  NA.string=getOption("xtable.NA.string", ""),\r
+  include.rownames=getOption("xtable.include.rownames", TRUE),\r
+  include.colnames=getOption("xtable.include.colnames", TRUE),\r
+  only.contents=getOption("xtable.only.contents", FALSE),\r
+  add.to.row=getOption("xtable.add.to.row", NULL),\r
+  sanitize.text.function=getOption("xtable.sanitize.text.function", NULL),\r
+  sanitize.rownames.function=getOption("xtable.sanitize.rownames.function", \r
+    sanitize.text.function),\r
+  sanitize.colnames.function=getOption("xtable.sanitize.colnames.function", \r
+    sanitize.text.function),\r
+  math.style.negative=getOption("xtable.math.style.negative", FALSE),\r
+  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
 \arguments{\r
   \item{x}{An object of class \code{"xtable"}.}\r
   \item{type}{Type of table to produce.  Possible values for \code{type} are \code{"latex"} or \code{"html"}.\r
@@ -58,6 +71,7 @@
   \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
   \item{...}{Additional arguments.  (Currently ignored.)}\r
 }\r
 \details{\r
@@ -69,6 +83,8 @@
 \r
   From version 1.4-3, all non-numeric columns are sanitized, and all LaTeX special characters are sanitised for LaTeX output.  See Section 3 of the \code{xtableGallery} vignette for an example of customising the sanitization.\r
   From version 1.4-4, the sanitization also applies to column names.  To remove any text sanitization, specify \code{sanitize.text.function=function(x){x}}.\r
+  \r
+  From version 1.6-1 the default values for the arguments other than \code{x} are obtainined using \code{getOption()}.  Hence the user can set the values once with \code{options()} rather than setting them in every call to \code{print.xtable()}.\r
 }\r
 \author{David Dahl \email{dahl@stat.tamu.edu} with contributions and suggestions from many others (see source code).}\r
 \references{\r
index 7211a83ef6e89346805b18d06f83a03075071068..41628acc3728390d339eab3e06f2f408de445c0d 100644 (file)
@@ -283,6 +283,20 @@ rownames(mat) <- "$y_{t-1}$"
 colnames(mat) <- c("$R^2$", "$\\\bar{R}^2$", "F-stat", "S.E.E", "DW")
 print(xtable(mat), type="latex", sanitize.text.function = function(x){x})
 
+## Demonstrate booktabs
+print(tli.table)
+print(tli.table , hline.after=c(-1,0))
+print(tli.table , hline.after=NULL)
+print(tli.table ,  add.to.row=list(pos=list(2), command=c("\\vspace{2mm} \n")))
+
+print(tli.table , booktabs=TRUE)
+print(tli.table , booktabs=TRUE, hline.after=c(-1,0))
+print(tli.table , booktabs=TRUE, hline.after=NULL)
+print(tli.table , booktabs=TRUE, 
+  add.to.row=list(pos=list(2), command=c("\\vspace{2mm} \n")))
+print(tli.table , booktabs=TRUE, add.to.row=list(pos=list(2), 
+  command=c("youhou\n")),tabular.environment = "longtable")
+
 \testonly{
   for(i in c("latex","html")) {
     outFileName <- paste("xtable.",ifelse(i=="latex","tex",i),sep="")