]> git.donarmstrong.com Git - xtable.git/commitdiff
Merge branch 'master' into repeat_caption_in_longtable repeat_caption_in_longtable
authorDon Armstrong <don@donarmstrong.com>
Mon, 5 Dec 2016 22:18:18 +0000 (14:18 -0800)
committerDon Armstrong <don@donarmstrong.com>
Mon, 5 Dec 2016 22:18:18 +0000 (14:18 -0800)
25 files changed:
pkg/DESCRIPTION
pkg/NAMESPACE
pkg/NEWS
pkg/R/print.xtable.R
pkg/R/sanitize.R [new file with mode: 0644]
pkg/R/table.attributes.R
pkg/R/toLatex.R
pkg/R/xtable.R
pkg/R/xtableFtable.R [new file with mode: 0644]
pkg/R/xtableList.R [new file with mode: 0644]
pkg/R/xtableMatharray.R [new file with mode: 0644]
pkg/man/print.xtable.Rd
pkg/man/print.xtableMatharray.Rd [new file with mode: 0644]
pkg/man/sanitize.Rd [new file with mode: 0644]
pkg/man/string.Rd
pkg/man/xtable-internal.Rd [new file with mode: 0644]
pkg/man/xtable.Rd
pkg/man/xtableFtable.Rd [new file with mode: 0644]
pkg/man/xtableList.Rd [new file with mode: 0644]
pkg/man/xtableMatharray.Rd [new file with mode: 0644]
pkg/tests/test.matharray.R [new file with mode: 0644]
pkg/tests/test.xtable.xtableFtable.R [new file with mode: 0644]
pkg/vignettes/OtherPackagesGallery.Rnw [new file with mode: 0644]
pkg/vignettes/listOfTablesGallery.Rnw [new file with mode: 0644]
pkg/vignettes/xtableGallery.Rnw

index 43273ee6e6abf585c3bdb712e8056523afbda623..8c20f5acd6e9e273c981290c837db9a5454fb871 100644 (file)
@@ -1,11 +1,11 @@
 Package: xtable
-Version: 1.8-0
-Date: 2015-10-22
+Version: 1.8-3
+Date: 2016-03-30
 Title: Export Tables to LaTeX or HTML
 Author: David B. Dahl <dahl@stat.byu.edu>
 Maintainer: David Scott <d.scott@auckland.ac.nz>
 Imports: stats, utils
-Suggests: knitr
+Suggests: knitr, lsmeans, spdep, splm, sphet, plm, zoo, survival
 VignetteBuilder: knitr
 Description: Coerce data to LaTeX and HTML tables.
 URL: http://xtable.r-forge.r-project.org/
index 07c343661081bd781b5dec9f94c7a9cd925cd7b5..f5c4c6987a5c21ca17ba87af5d236e8d57813866 100644 (file)
@@ -3,11 +3,19 @@ importFrom("stats", "anova", "as.ts", "cycle", "end", "frequency",
            "na.omit", "pchisq", "start", "time")
 importFrom("utils", "packageDescription")
 export("caption<-", "caption", "label", "label<-",
-   "align<-", "align", "digits<-", "digits", "display<-",
-   "display", "xtable", "print.xtable", "toLatex.xtable",
-   "autoformat", "xalign", "xdigits", "xdisplay")
+       "align<-", "align", "digits<-", "digits", "display<-",
+       "display", "xtable",
+       "xtableMatharray","xtableList", "xtableLSMeans",
+       "print.xtable", "print.xtableMatharray", "print.xtableList",
+       "xtableFtable", "print.xtableFtable",
+       "toLatex.xtable",
+       "autoformat", "xalign", "xdigits", "xdisplay",
+       "sanitize", "sanitize.numbers", "sanitize.final", "as.is", "as.math")
 
 S3method("print", "xtable")
+S3method("print", "xtableMatharray")
+S3method("print", "xtableList")
+S3method("print", "xtableFtable")
 S3method("toLatex", "xtable")
 
 S3method("caption<-", "xtable")
@@ -38,3 +46,17 @@ S3method("xtable", "summary.prcomp")
 S3method("xtable", "coxph")
 S3method("xtable", "ts")
 S3method("xtable", "zoo")
+S3method("xtable", "sarlm")
+S3method("xtable", "summary.sarlm")
+S3method("xtable", "gmsar")
+S3method("xtable", "summary.gmsar")
+S3method("xtable", "stsls")
+S3method("xtable", "summary.stsls")
+S3method("xtable", "sarlm.pred")
+S3method("xtable", "lagImpact")
+S3method("xtable", "splm")
+S3method("xtable", "summary.splm")
+S3method("xtable", "sphet")
+S3method("xtable", "summary.sphet")
+S3method("xtable", "spautolm")
+S3method("xtable", "summary.spautolm")
index edf19ebdda638e0b7346072b3c31d0878c8447c6..dcd41bf32ffd687b69b3bcfad4cc55caa8801054 100644 (file)
--- a/pkg/NEWS
+++ b/pkg/NEWS
@@ -1,4 +1,48 @@
-1.8-0
+1.8-3 (NOT YET SUBMITTED TO CRAN)
+  * Corrected call to print.xtable inside print.xtableFtable included
+    arguments from call to print.xtableFtable. Absence of size
+    argument was advised by Lluis Ramon, email March 4, 2016    
+  * Added patch from Martin Gubri, martin.gubri@framasoft.org to
+    enable use of lagImpactMat from spdep in xtable method lagImpact.
+  * Added patch to code in OtherPackagesGallery.Rnw supplied by Martin
+    Gubri to avoid warnings in the spdep package example. Also fixed the
+    vignette index entry.
+  
+1.8-2 (2016-02-05)
+  * Added function print.xtableMatharray to enable easy creation of
+    LaTeX code to enable an array to be included in a document.
+  * Added example to the gallery using sanitizing headings and row
+    names to produce large bold headings and italic row names.
+  * Added code from Martin Gubri, martin.gubri@framasoft.org, to produce
+    tables from the spatial econometrics packages, spdep, splm, and
+    sphet.
+  * Extracted sanitize functions from print.xtable as stand-alone
+    functions, and exported them. Added helper functions as.is and
+    as.math for assistance with sanitization (supplied by Stefan
+    Edwards <sme@iysik.com> in Feature Request #5303).
+  * Added option to produce math style exponents when sanitizing
+    numbers, as suggested by Don Armstrong <don@donarmstrong.com>, who
+    also provided code
+  * Fixed bug #6907. Warning was created when the data frame as no
+    rows for type is 'html'. Added a test to create the matrix
+    requested specially in that case. Original code was
+    BTD2 <- matrix(align.tmp[(2-pos):(ncol(x)+1)],
+                   nrow = nrow(x), ncol = ncol(x)+pos, byrow = TRUE)
+    which created a matrix with no rows, but gave a warning when
+    there were no rows in the data frame being processed.
+  * Fixed bug #6260. Accepted the change suggested by Claudius
+    Loehnert, which was to replace { and } by \begingroup and
+    \endgroup respectively as the delimiters when size was to changed
+    in a table.
+  * Added functions xtableList and print.xtableList to produce
+    composite tables consisting of a number of subtables.
+  * Added xtableFtable and print.xtableFtable to format flat tables
+    produced by ftable. Included examples in the xtable gallery.
+  * Produced new vignettes: 'The xtableList Gallery' to illustrate
+    xtableList and print.xtableList; and 'The Other Packages Gallery'
+    to illustrate methods for classes of objects from other packages.
+
+1.8-0 (2015-11-02)
   * autoformat, xalign, xdigits, xdisplay from Arni Magnusson, added
     along with help file. Feature request #5686.
   * New argument 'auto' in xtable(), to call xalign, xdigits, and
index d748924366c5a4ecc434a8aa92eb2e7309e9b7da..aa1079dd73369d2c0122cfaafaf1a4118b7749e6 100644 (file)
@@ -58,691 +58,607 @@ print.xtable <- function(x,
   timestamp = getOption("xtable.timestamp", date()),\r
   ...)\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\r
-    ## 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\r
-    ## hline.after vector\r
-    ## If you do not want any \hline inside the data, set hline.after to NULL\r
-    ## PHEADER instead the string '\\hline\n' is used in the code\r
-    ## Now hline.after counts how many time a position appear\r
-    ## I left an automatic PHEADER in the longtable is this correct?\r
-\r
-    ## Claudio Agostinelli <claudio@unive.it> dated 2006-07-28 include.rownames,\r
-    ## include.colnames\r
-    pos <- 0\r
-    if (include.rownames) pos <- 1\r
-\r
-    ## Claudio Agostinelli <claudio@unive.it> dated 2006-07-28\r
-    ## hline.after checks\r
-    if (any(hline.after < -1) | any(hline.after > nrow(x))) {\r
-        stop("'hline.after' must be inside [-1, nrow(x)]")\r
-    }\r
-\r
-    ## Claudio Agostinelli <claudio@unive.it> dated 2006-07-28\r
-    ## add.to.row checks\r
-    if (!is.null(add.to.row)) {\r
-        if (is.list(add.to.row) && length(add.to.row) == 2) {\r
-            if (is.null(names(add.to.row))) {\r
-                names(add.to.row) <- c('pos', 'command')\r
-            } else if (any(sort(names(add.to.row))!= c('command', 'pos'))) {\r
-                stop("the names of the elements of 'add.to.row' must be 'pos' and 'command'")\r
-            }\r
-            if (is.list(add.to.row$pos) && is.vector(add.to.row$command,\r
-                                                     mode = 'character')) {\r
-                if ((npos <- length(add.to.row$pos)) !=\r
-                    length(add.to.row$command)) {\r
-                    stop("the length of 'add.to.row$pos' must be equal to the length of 'add.to.row$command'")\r
-                }\r
-                if (any(unlist(add.to.row$pos) < -1) |\r
-                    any(unlist(add.to.row$pos) > nrow(x))) {\r
-                    stop("the values in add.to.row$pos must be inside the interval [-1, nrow(x)]")\r
-                }\r
-            } else {\r
-                stop("the first argument ('pos') of 'add.to.row' must be a list, the second argument ('command') must be a vector of mode character")\r
-            }\r
-        } else {\r
-            stop("'add.to.row' argument must be a list of length 2")\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\r
+  ## 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\r
+  ## hline.after vector\r
+  ## If you do not want any \hline inside the data, set hline.after to NULL\r
+  ## PHEADER instead the string '\\hline\n' is used in the code\r
+  ## Now hline.after counts how many time a position appear\r
+  ## I left an automatic PHEADER in the longtable is this correct?\r
+  \r
+  ## Claudio Agostinelli <claudio@unive.it> dated 2006-07-28 include.rownames,\r
+  ## include.colnames\r
+  pos <- 0\r
+  if (include.rownames) pos <- 1\r
+  \r
+  ## Claudio Agostinelli <claudio@unive.it> dated 2006-07-28\r
+  ## hline.after checks\r
+  if (any(hline.after < -1) | any(hline.after > nrow(x))) {\r
+    stop("'hline.after' must be inside [-1, nrow(x)]")\r
+  }\r
+  \r
+  ## Claudio Agostinelli <claudio@unive.it> dated 2006-07-28\r
+  ## add.to.row checks\r
+  if (!is.null(add.to.row)) {\r
+    if (is.list(add.to.row) && length(add.to.row) == 2) {\r
+      if (is.null(names(add.to.row))) {\r
+        names(add.to.row) <- c('pos', 'command')\r
+      } else if (any(sort(names(add.to.row))!= c('command', 'pos'))) {\r
+        stop("the names of the elements of 'add.to.row' must be 'pos' and 'command'")\r
+      }\r
+      if (is.list(add.to.row$pos) && is.vector(add.to.row$command,\r
+                                               mode = 'character')) {\r
+        if ((npos <- length(add.to.row$pos)) !=\r
+            length(add.to.row$command)) {\r
+          stop("the length of 'add.to.row$pos' must be equal to the length of 'add.to.row$command'")\r
+        }\r
+        if (any(unlist(add.to.row$pos) < -1) |\r
+            any(unlist(add.to.row$pos) > nrow(x))) {\r
+          stop("the values in add.to.row$pos must be inside the interval [-1, nrow(x)]")\r
         }\r
+      } else {\r
+        stop("the first argument ('pos') of 'add.to.row' must be a list, the second argument ('command') must be a vector of mode character")\r
+      }\r
     } else {\r
-        add.to.row <- list(pos = list(),\r
-                           command = vector(length = 0, mode = "character"))\r
-        npos <- 0\r
+      stop("'add.to.row' argument must be a list of length 2")\r
     }\r
-\r
-    ## 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
-        ## Original code before changes in version 1.6-1\r
-        ## PHEADER <- "\\hline\n"\r
-\r
-        ## booktabs code from Matthieu Stigler <matthieu.stigler@gmail.com>,\r
-        ## 1 Feb 2012\r
-        if(!booktabs){\r
-            PHEADER <- "\\hline\n"\r
-        } else {\r
-            ## This code replaced to fix bug #2309, David Scott, 8 Jan 2014\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
-            if (is.null(hline.after)){\r
-                PHEADER <- ""\r
-            } else {\r
-                hline.after <- sort(hline.after)\r
-                PHEADER <- rep("\\midrule\n", length(hline.after))\r
-                if (hline.after[1] == -1) {\r
-                    PHEADER[1] <- "\\toprule\n"\r
-                }\r
-                if (hline.after[length(hline.after)] == nrow(x)) {\r
-                    PHEADER[length(hline.after)] <- "\\bottomrule\n"\r
-                }\r
-            }\r
-        }\r
+  } else {\r
+    add.to.row <- list(pos = list(),\r
+                       command = vector(length = 0, mode = "character"))\r
+    npos <- 0\r
+  }\r
+  \r
+  ## 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
+    ## Original code before changes in version 1.6-1\r
+    ## PHEADER <- "\\hline\n"\r
+    \r
+    ## booktabs code from Matthieu Stigler <matthieu.stigler@gmail.com>,\r
+    ## 1 Feb 2012\r
+    if(!booktabs){\r
+      PHEADER <- "\\hline\n"\r
     } else {\r
+      ## This code replaced to fix bug #2309, David Scott, 8 Jan 2014\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
+      if (is.null(hline.after)){\r
         PHEADER <- ""\r
-    }\r
-\r
-        lastcol <- rep(" ", nrow(x)+2)\r
-    if (!is.null(hline.after)) {\r
-        ## booktabs change - Matthieu Stigler: fill the hline arguments\r
-        ## 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
+      } else {\r
+        hline.after <- sort(hline.after)\r
+        PHEADER <- rep("\\midrule\n", length(hline.after))\r
+        if (hline.after[1] == -1) {\r
+          PHEADER[1] <- "\\toprule\n"\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
-            freq <- table(addpos)\r
-            addpos <- unique(addpos)\r
-            for (j in 1:length(addpos)) {\r
-                lastcol[addpos[j]+2] <- paste(lastcol[addpos[j]+2],\r
-                                              paste(rep(add.to.row$command[i],\r
-                                                        freq[j]),\r
-                                                sep = "", collapse = ""),\r
-                                              sep = " ")\r
-            }\r
+        if (hline.after[length(hline.after)] == nrow(x)) {\r
+          PHEADER[length(hline.after)] <- "\\bottomrule\n"\r
         }\r
+      }\r
     }\r
-\r
-    if (length(type)>1) stop("\"type\" must have length 1")\r
-    type <- tolower(type)\r
-    if (!all(!is.na(match(type, c("latex","html"))))) {\r
-        stop("\"type\" must be in {\"latex\", \"html\"}")\r
-    }\r
-    ## Disabling the check on known floating environments as many users\r
-    ## want to use additional environments.\r
-    #    if (!all(!is.na(match(floating.environment,\r
-    #                          c("table","table*","sidewaystable",\r
-    #                            "margintable"))))) {\r
-    #        stop("\"type\" must be in {\"table\", \"table*\", \"sidewaystable\", \"margintable\"}")\r
-    #    }\r
-    if (("margintable" %in% floating.environment)\r
-        & (!is.null(table.placement))) {\r
-        warning("margintable does not allow for table placement; setting table.placement to NULL")\r
-        table.placement <- NULL\r
+  } else {\r
+    PHEADER <- ""\r
+  }\r
+  \r
+  lastcol <- rep(" ", nrow(x)+2)\r
+  if (!is.null(hline.after)) {\r
+    ## booktabs change - Matthieu Stigler: fill the hline arguments\r
+    ## 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
-    if (!is.null(table.placement) &&\r
-        !all(!is.na(match(unlist(strsplit(table.placement,  split = "")),\r
-                          c("H","h","t","b","p","!"))))) {\r
-        stop("\"table.placement\" must contain only elements of {\"h\",\"t\",\"b\",\"p\",\"!\"}")\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
+      freq <- table(addpos)\r
+      addpos <- unique(addpos)\r
+      for (j in 1:length(addpos)) {\r
+        lastcol[addpos[j]+2] <- paste(lastcol[addpos[j]+2],\r
+                                      paste(rep(add.to.row$command[i],\r
+                                                freq[j]),\r
+                                            sep = "", collapse = ""),\r
+                                      sep = " ")\r
+      }\r
     }\r
-    if (!all(!is.na(match(caption.placement, c("bottom","top"))))) {\r
-        stop("\"caption.placement\" must be either {\"bottom\",\"top\"}")\r
+  }\r
+  \r
+  if (length(type)>1) stop("\"type\" must have length 1")\r
+  type <- tolower(type)\r
+  if (!all(!is.na(match(type, c("latex","html"))))) {\r
+    stop("\"type\" must be in {\"latex\", \"html\"}")\r
+  }\r
+  ## Disabling the check on known floating environments as many users\r
+  ## want to use additional environments.\r
+  ##    if (!all(!is.na(match(floating.environment,\r
+  ##                          c("table","table*","sidewaystable",\r
+  ##                            "margintable"))))) {\r
+  ##        stop("\"type\" must be in {\"table\", \"table*\", \"sidewaystable\", \"margintable\"}")\r
+  ##    }\r
+  if (("margintable" %in% floating.environment)\r
+      & (!is.null(table.placement))) {\r
+    warning("margintable does not allow for table placement; setting table.placement to NULL")\r
+    table.placement <- NULL\r
+  }\r
+  if (!is.null(table.placement) &&\r
+      !all(!is.na(match(unlist(strsplit(table.placement,  split = "")),\r
+                        c("H","h","t","b","p","!"))))) {\r
+    stop("\"table.placement\" must contain only elements of {\"h\",\"t\",\"b\",\"p\",\"!\"}")\r
+  }\r
+  if (!all(!is.na(match(caption.placement, c("bottom","top"))))) {\r
+    stop("\"caption.placement\" must be either {\"bottom\",\"top\"}")\r
+  }\r
+  \r
+  if (type == "latex") {\r
+    BCOMMENT <- "% "\r
+    ECOMMENT <- "\n"\r
+    ## See e-mail from "John S. Walker <jsw9c@uic.edu>" dated 5-19-2003\r
+    ## regarding "texfloat"\r
+    ## See e-mail form "Fernando Henrique Ferraz P. da Rosa"\r
+    ## <academic@feferraz.net>" dated 10-28-2005 regarding "longtable"\r
+    if ( tabular.environment == "longtable" & floating == TRUE ) {\r
+      warning("Attempt to use \"longtable\" with floating = TRUE. Changing to FALSE.")\r
+      floating <- FALSE\r
     }\r
-\r
-    if (type == "latex") {\r
-        BCOMMENT <- "% "\r
-        ECOMMENT <- "\n"\r
-        ## See e-mail from "John S. Walker <jsw9c@uic.edu>" dated 5-19-2003\r
-        ## regarding "texfloat"\r
-        ## See e-mail form "Fernando Henrique Ferraz P. da Rosa"\r
-        ## <academic@feferraz.net>" dated 10-28-2005 regarding "longtable"\r
-        if ( tabular.environment == "longtable" & floating == TRUE ) {\r
-            warning("Attempt to use \"longtable\" with floating = TRUE. Changing to FALSE.")\r
-            floating <- FALSE\r
-        }\r
-        if ( floating == TRUE ) {\r
-            ## See e-mail from "Pfaff, Bernhard <Bernhard.Pfaff@drkw.com>"\r
-            ## dated 7-09-2003 regarding "suggestion for an amendment of\r
-            ## the source"\r
-            ## See e-mail from "Mitchell, David"\r
-            ## <David.Mitchell@dotars.gov.au>" dated 2003-07-09 regarding\r
-            ## "Additions to R xtable package"\r
-            ## See e-mail from "Garbade, Sven"\r
-            ## <Sven.Garbade@med.uni-heidelberg.de> dated 2006-05-22\r
-            ## regarding the floating environment.\r
-            BTABLE <- paste("\\begin{", floating.environment, "}",\r
-                            ifelse(!is.null(table.placement),\r
-                                   paste("[", table.placement, "]", sep = ""),\r
-                                   ""), "\n", sep = "")\r
-            if ( is.null(latex.environments) ||\r
-                (length(latex.environments) == 0) ) {\r
-                BENVIRONMENT <- ""\r
-                EENVIRONMENT <- ""\r
-            } else {\r
-                BENVIRONMENT <- ""\r
-                EENVIRONMENT <- ""\r
-                if ("center" %in% latex.environments){\r
-                    BENVIRONMENT <- paste(BENVIRONMENT, "\\centering\n",\r
-                                          sep = "")\r
-                }\r
-                for (i in 1:length(latex.environments)) {\r
-                    if (latex.environments[i] == "") next\r
-                    if (latex.environments[i] != "center"){\r
-                        BENVIRONMENT <- paste(BENVIRONMENT,\r
-                                              "\\begin{", latex.environments[i],\r
-                                              "}\n", sep = "")\r
-                        EENVIRONMENT <- paste("\\end{", latex.environments[i],\r
-                                              "}\n", EENVIRONMENT, sep = "")\r
-                    }\r
-                }\r
-            }\r
-            ETABLE <- paste("\\end{", floating.environment, "}\n", sep = "")\r
-        } else {\r
-            BTABLE <- ""\r
-            ETABLE <- ""\r
-            BENVIRONMENT <- ""\r
-            EENVIRONMENT <- ""\r
-        }\r
-\r
-        tmp.index.start <- 1\r
-        if ( ! include.rownames ) {\r
-            while ( attr(x, "align", exact = TRUE)[tmp.index.start] == '|' )\r
-                tmp.index.start <- tmp.index.start + 1\r
-            tmp.index.start <- tmp.index.start + 1\r
-        }\r
-        ## Added "width" argument for use with "tabular*" or\r
-        ## "tabularx" environments - CR, 7/2/12\r
-        if (is.null(width)){\r
-            WIDTH <-""\r
-        } else if (is.element(tabular.environment,\r
-                              c("tabular", "longtable"))){\r
-            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.")\r
-            WIDTH <- ""\r
-        } else {\r
-            WIDTH <- paste("{", width, "}", sep = "")\r
-        }\r
-\r
-        BTABULAR <-\r
-            paste("\\begin{", tabular.environment, "}",\r
-                  WIDTH, "{",\r
-                  paste(c(attr(x, "align",\r
-                               exact = TRUE)[\r
-                               tmp.index.start:length(attr(x, "align",\r
-                                                           exact = TRUE))],\r
-                          "}\n"),\r
-                        sep = "", collapse = ""),\r
-                  sep = "")\r
-\r
-        ## fix 10-26-09 (robert.castelo@upf.edu) the following\r
-        ## 'if' condition is added here to support\r
-        ## a caption on the top of a longtable\r
-        if (tabular.environment == "longtable" && caption.placement == "top") {\r
-            if (is.null(short.caption)){\r
-                BCAPTION <- "\\caption{"\r
-            } else {\r
-                BCAPTION <- paste("\\caption[", short.caption, "]{", sep = "")\r
-            }\r
-            ECAPTION <- "} \\\\ \n"\r
-            if ((!is.null(caption)) && (type == "latex")) {\r
-                BTABULAR <- paste(BTABULAR,  BCAPTION, caption, ECAPTION,\r
-                                  sep = "")\r
-            }\r
-        }\r
-        ## Claudio Agostinelli <claudio@unive.it> dated 2006-07-28\r
-        ## add.to.row position -1\r
-        BTABULAR <- paste(BTABULAR, lastcol[1], sep = "")\r
-        ## the \hline at the end, if present, is set in full matrix\r
-        ETABULAR <- paste("\\end{", tabular.environment, "}\n", sep = "")\r
-\r
-        ## Add scalebox - CR, 7/2/12\r
-        if (!is.null(scalebox)){\r
-            BTABULAR <- paste("\\scalebox{", scalebox, "}{\n", BTABULAR,\r
-                              sep = "")\r
-            ETABULAR <- paste(ETABULAR, "}\n", sep = "")\r
-        }\r
-\r
-        ## BSIZE contributed by Benno <puetz@mpipsykl.mpg.de> in e-mail\r
-        ## dated Wednesday, December 01, 2004\r
-        if (is.null(size) || !is.character(size)) {\r
-            BSIZE <- ""\r
-            ESIZE <- ""\r
-        } else {\r
-            if(length(grep("^\\\\", size)) == 0){\r
-                size <- paste("\\", size, sep = "")\r
-            }\r
-            BSIZE <- paste("{", size, "\n", sep = "")\r
-            ESIZE <- "}\n"\r
-        }\r
-        BLABEL <- "\\label{"\r
-        ELABEL <- "}\n"\r
-        ## Added caption width (jeff.laake@nooa.gov)\r
-           if(!is.null(caption.width)){\r
-               BCAPTION <- paste("\\parbox{",caption.width,"}{",sep="")\r
-               ECAPTION <- "}"\r
-           } else {\r
-               BCAPTION <- NULL\r
-               ECAPTION <- NULL\r
-           }\r
-           if (is.null(short.caption)){\r
-                  BCAPTION <- paste(BCAPTION,"\\caption{",sep="")\r
-           } else {\r
-                  BCAPTION <- paste(BCAPTION,"\\caption[", short.caption, "]{", sep="")\r
-           }\r
-        ECAPTION <- paste(ECAPTION,"} \n",sep="")\r
-        BROW <- ""\r
-        EROW <- " \\\\ \n"\r
-        BTH <- ""\r
-        ETH <- ""\r
-        STH <- " & "\r
-        BTD1 <- " & "\r
-        BTD2 <- ""\r
-        BTD3 <- ""\r
-        ETD  <- ""\r
-        ## Based on contribution from Jonathan Swinton\r
-        ## <jonathan@swintons.net> in e-mail dated Wednesday, January 17, 2007\r
-        sanitize <- function(str) {\r
-            result <- str\r
-            result <- gsub("\\\\", "SANITIZE.BACKSLASH", result)\r
-            result <- gsub("$", "\\$", result, fixed = TRUE)\r
-            result <- gsub(">", "$>$", result, fixed = TRUE)\r
-            result <- gsub("<", "$<$", result, fixed = TRUE)\r
-            result <- gsub("|", "$|$", result, fixed = TRUE)\r
-            result <- gsub("{", "\\{", result, fixed = TRUE)\r
-            result <- gsub("}", "\\}", result, fixed = TRUE)\r
-            result <- gsub("%", "\\%", result, fixed = TRUE)\r
-            result <- gsub("&", "\\&", result, fixed = TRUE)\r
-            result <- gsub("_", "\\_", result, fixed = TRUE)\r
-            result <- gsub("#", "\\#", result, fixed = TRUE)\r
-            result <- gsub("^", "\\verb|^|", result, fixed = TRUE)\r
-            result <- gsub("~", "\\~{}", result, fixed = TRUE)\r
-            result <- gsub("SANITIZE.BACKSLASH", "$\\backslash$",\r
-                           result, fixed = TRUE)\r
-            return(result)\r
-        }\r
-        sanitize.numbers <- function(x) {\r
-            result <- x\r
-            if ( math.style.negative ) {\r
-                ## Jake Bowers <jwbowers@illinois.edu> in e-mail\r
-                ## from 2008-08-20 suggested disabling this feature to avoid\r
-                ## problems with LaTeX's dcolumn package.\r
-                ## by Florian Wickelmaier <florian.wickelmaier@uni-tuebingen.de>\r
-                ## in e-mail from 2008-10-03 requested the ability to use the\r
-                ## old behavior.\r
-                for(i in 1:length(x)) {\r
-                    result[i] <- gsub("-", "$-$", result[i], fixed = TRUE)\r
-                }\r
-            }\r
-            if (is.logical(math.style.exponents) && ! math.style.exponents ) {\r
-            } else if (is.logical(math.style.exponents) && math.style.exponents ||\r
-                       math.style.exponents == "$$"\r
-                       ) {\r
-                for(i in 1:length(x)) {\r
-                    result[i] <- gsub("^\\$?(-?)\\$?([0-9.]+)[eE]\\$?(-?)\\+?\\$?0*(\\d+)$",\r
-                                      "$\\1\\2 \\\\times 10^{\\3\\4}$", result[i])\r
-                }\r
-            } else if (math.style.exponents == "ensuremath") {\r
-                for(i in 1:length(x)) {\r
-                    result[i] <- gsub("^\\$?(-?)\\$?([0-9.]+)[eE]\\$?(-?)\\+?\\$?0*(\\d+)$",\r
-                                      "\\\\ensuremath{\\1\\2 \\\\times 10^{\\3\\4}}", result[i])\r
-                }\r
-            } else if (math.style.exponents == "UTF8" ||\r
-                       math.style.exponents == "UTF-8") {\r
-                for(i in 1:length(x)) {\r
-                    ## this code turns 1e5 into 1×10⁵x\r
-                    if (all(grepl("^\\$?(-?)\\$?([0-9.]+)[eE]\\$?(-?)\\+?\\$?0*(\\d+)$",result[i]))) {\r
-                        temp <- strsplit(result[i],"eE",result[i])\r
-                        result[i] <-\r
-                            paste0(temp[1],\r
-                                   "\u00d710",\r
-                                   chartr("-1234567890","\u207b\u00b9\u00b2\u00b3\u2074\u2075\u20746\u20747\u20748\u20749\u2070",temp[2]))\r
-                    }\r
-                }\r
-            }\r
-            return(result)\r
-        }\r
-        sanitize.final <- function(result) {\r
-            return(result)\r
-        }\r
-    } else {\r
-        BCOMMENT <- "<!-- "\r
-        ECOMMENT <- " -->\n"\r
-        BTABLE <- paste("<table ", html.table.attributes, ">\n", sep = "")\r
-        ETABLE <- "</table>\n"\r
+    if ( floating == TRUE ) {\r
+      ## See e-mail from "Pfaff, Bernhard <Bernhard.Pfaff@drkw.com>"\r
+      ## dated 7-09-2003 regarding "suggestion for an amendment of\r
+      ## the source"\r
+      ## See e-mail from "Mitchell, David"\r
+      ## <David.Mitchell@dotars.gov.au>" dated 2003-07-09 regarding\r
+      ## "Additions to R xtable package"\r
+      ## See e-mail from "Garbade, Sven"\r
+      ## <Sven.Garbade@med.uni-heidelberg.de> dated 2006-05-22\r
+      ## regarding the floating environment.\r
+      BTABLE <- paste("\\begin{", floating.environment, "}",\r
+                      ifelse(!is.null(table.placement),\r
+                             paste("[", table.placement, "]", sep = ""),\r
+                             ""), "\n", sep = "")\r
+      if ( is.null(latex.environments) ||\r
+           (length(latex.environments) == 0) ) {\r
         BENVIRONMENT <- ""\r
         EENVIRONMENT <- ""\r
-        BTABULAR <- ""\r
-        ETABULAR <- ""\r
-        BSIZE <- ""\r
-        ESIZE <- ""\r
-        BLABEL <- "<a name="\r
-        ELABEL <- "></a>\n"\r
-        BCAPTION <- paste("<caption align=\"", caption.placement, "\"> ",\r
-                          sep = "")\r
-        ECAPTION <- " </caption>\n"\r
-        BROW <- "<tr>"\r
-        EROW <- " </tr>\n"\r
-        BTH <- " <th> "\r
-        ETH <- " </th> "\r
-        STH <- " </th> <th> "\r
-        BTD1 <- " <td align=\""\r
-        align.tmp <- attr(x, "align", exact = TRUE)\r
-        align.tmp <- align.tmp[align.tmp!="|"]\r
-        BTD2 <- matrix(align.tmp[(2-pos):(ncol(x)+1)],\r
-                       nrow = nrow(x), ncol = ncol(x)+pos, byrow = TRUE)\r
-        ## Based on contribution from Jonathan Swinton <jonathan@swintons.net>\r
-        ## in e-mail dated Wednesday, January 17, 2007\r
-        BTD2[regexpr("^p", BTD2)>0] <- "left"\r
-        BTD2[BTD2 == "r"] <- "right"\r
-        BTD2[BTD2 == "l"] <- "left"\r
-        BTD2[BTD2 == "c"] <- "center"\r
-        BTD3 <- "\"> "\r
-        ETD  <- " </td>"\r
-        sanitize <- function(str) {\r
-            result <- str\r
-            ## Changed as suggested in bug report #2795\r
-            ## That is replacement of "&" is "&amp;"\r
-            ## instead of previous "&amp" etc\r
-            ## result <- gsub("&", "&amp ", result, fixed = TRUE)\r
-            ## result <- gsub(">", "&gt ", result, fixed = TRUE)\r
-            ## result <- gsub("<", "&lt ", result, fixed = TRUE)\r
-            result <- gsub("&", "&amp;", result, fixed = TRUE)\r
-            result <- gsub(">", "&gt;", result, fixed = TRUE)\r
-            result <- gsub("<", "&lt;", result, fixed = TRUE)\r
-            ## Kurt Hornik <Kurt.Hornik@wu-wien.ac.at> on 2006/10/05\r
-            ## recommended not escaping underscores.\r
-            ## result <- gsub("_", "\\_", result, fixed=TRUE)\r
-            return(result)\r
-        }\r
-        sanitize.numbers <- function(x) {\r
-            return(x)\r
+      } else {\r
+        BENVIRONMENT <- ""\r
+        EENVIRONMENT <- ""\r
+        if ("center" %in% latex.environments){\r
+          BENVIRONMENT <- paste(BENVIRONMENT, "\\centering\n",\r
+                                sep = "")\r
         }\r
-        sanitize.final <- function(result) {\r
-            ## Suggested by Uwe Ligges <ligges@statistik.uni-dortmund.de>\r
-            ## in e-mail dated 2005-07-30.\r
-            result$text <- gsub("  *", " ",  result$text, fixed = TRUE)\r
-            result$text <- gsub(' align="left"',  "", result$text,\r
-                                fixed = TRUE)\r
-            return(result)\r
+        for (i in 1:length(latex.environments)) {\r
+          if (latex.environments[i] == "") next\r
+          if (latex.environments[i] != "center"){\r
+            BENVIRONMENT <- paste(BENVIRONMENT,\r
+                                  "\\begin{", latex.environments[i],\r
+                                  "}\n", sep = "")\r
+            EENVIRONMENT <- paste("\\end{", latex.environments[i],\r
+                                  "}\n", EENVIRONMENT, sep = "")\r
+          }\r
         }\r
+      }\r
+      ETABLE <- paste("\\end{", floating.environment, "}\n", sep = "")\r
+    } else {\r
+      BTABLE <- ""\r
+      ETABLE <- ""\r
+      BENVIRONMENT <- ""\r
+      EENVIRONMENT <- ""\r
     }\r
-\r
-    result <- string("", file = file, append = append)\r
-    info <- R.Version()\r
-    ## modified Claudio Agostinelli <claudio@unive.it> dated 2006-07-28\r
-    ## to set automatically the package version\r
-       if (comment){\r
-        result <- result + BCOMMENT + type + " table generated in " +\r
-              info$language + " " + info$major + "." + info$minor +\r
-              " by xtable " +  packageDescription('xtable')$Version +\r
-              " package" + ECOMMENT\r
-        if (!is.null(timestamp)){\r
-            result <- result + BCOMMENT + timestamp + ECOMMENT\r
-        }\r
+    \r
+    tmp.index.start <- 1\r
+    if ( ! include.rownames ) {\r
+      while ( attr(x, "align", exact = TRUE)[tmp.index.start] == '|' )\r
+        tmp.index.start <- tmp.index.start + 1\r
+      tmp.index.start <- tmp.index.start + 1\r
     }\r
-    ## Claudio Agostinelli <claudio@unive.it> dated 2006-07-28 only.contents\r
-    if (!only.contents) {\r
-        result <- result + BTABLE\r
-        result <- result + BENVIRONMENT\r
-        if ( floating == TRUE ) {\r
-            if ((!is.null(caption)) &&\r
-                (type == "html" ||caption.placement == "top")) {\r
-                result <- result + BCAPTION + caption + ECAPTION\r
-            }\r
-            if (!is.null(attr(x, "label", exact = TRUE)) &&\r
-                (type == "latex" && caption.placement == "top")) {\r
-                result <- result + BLABEL +\r
-                          attr(x, "label", exact = TRUE) + ELABEL\r
-            }\r
-        }\r
-        result <- result + BSIZE\r
-        result <- result + BTABULAR\r
+    ## Added "width" argument for use with "tabular*" or\r
+    ## "tabularx" environments - CR, 7/2/12\r
+    if (is.null(width)){\r
+      WIDTH <-""\r
+    } else if (is.element(tabular.environment,\r
+                          c("tabular", "longtable"))){\r
+      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.")\r
+      WIDTH <- ""\r
+    } else {\r
+      WIDTH <- paste("{", width, "}", sep = "")\r
+    }\r
+    \r
+    BTABULAR <-\r
+      paste("\\begin{", tabular.environment, "}",\r
+            WIDTH, "{",\r
+            paste(c(attr(x, "align",\r
+                         exact = TRUE)[\r
+              tmp.index.start:length(attr(x, "align",\r
+                                          exact = TRUE))],\r
+              "}\n"),\r
+              sep = "", collapse = ""),\r
+            sep = "")\r
+    \r
+    ## fix 10-26-09 (robert.castelo@upf.edu) the following\r
+    ## 'if' condition is added here to support\r
+    ## a caption on the top of a longtable\r
+    if (tabular.environment == "longtable" && caption.placement == "top") {\r
+      if (is.null(short.caption)){\r
+        BCAPTION <- "\\caption{"\r
+      } else {\r
+        BCAPTION <- paste("\\caption[", short.caption, "]{", sep = "")\r
+      }\r
+      ECAPTION <- "} \\\\ \n"\r
+      if ((!is.null(caption)) && (type == "latex")) {\r
+        BTABULAR <- paste(BTABULAR,  BCAPTION, caption, ECAPTION,\r
+                          sep = "")\r
+      }\r
     }\r
     ## Claudio Agostinelli <claudio@unive.it> dated 2006-07-28\r
-    ## include.colnames, include.rownames\r
-    if (include.colnames) {\r
-        COLNAMES <- string("", file = file, append = append)\r
-\r
-        COLNAMES <- COLNAMES + BROW + BTH\r
-        if (include.rownames) {\r
-            COLNAMES <- COLNAMES + STH\r
-       }\r
-        ## David G. Whiting in e-mail 2007-10-09\r
-        if (is.null(sanitize.colnames.function)) {\r
-            CNAMES <- sanitize(names(x))\r
-       } else {\r
-            CNAMES <- sanitize.colnames.function(names(x))\r
-       }\r
-        if (rotate.colnames) {\r
-            ##added by Markus Loecher, 2009-11-16\r
-            CNAMES <- paste("\\begin{sideways}", CNAMES, "\\end{sideways}")\r
-       }\r
-        COLNAMES <- COLNAMES + paste(CNAMES, collapse = STH)\r
-\r
-        COLNAMES <- COLNAMES + ETH + EROW\r
-        result <- result + COLNAMES\r
-        if (tabular.environment=="longtable") {\r
-            result <- result + "\\endfirsthead\n"\r
-            if (booktabs) {\r
-                if (!is.null(caption)) {\r
-                    result <- result + "\\caption[]{"+caption+"} \\\\\n"\r
-                }\r
-                result <- result + "\\toprule\n"+ COLNAMES + "\\midrule\n\\endhead\n"\r
-            } else {\r
-                if (!is.null(caption)) {\r
-                    result <- result + "\\caption[]{"+caption+"}\n"\r
-                }\r
-                result <- result + COLNAMES + "\\endhead\n"\r
-            }\r
-        }\r
+    ## add.to.row position -1\r
+    BTABULAR <- paste(BTABULAR, lastcol[1], sep = "")\r
+    ## the \hline at the end, if present, is set in full matrix\r
+    ETABULAR <- paste("\\end{", tabular.environment, "}\n", sep = "")\r
+    \r
+    ## Add scalebox - CR, 7/2/12\r
+    if (!is.null(scalebox)){\r
+      BTABULAR <- paste("\\scalebox{", scalebox, "}{\n", BTABULAR,\r
+                        sep = "")\r
+      ETABULAR <- paste(ETABULAR, "}\n", sep = "")\r
     }\r
-\r
-    cols <- matrix("", nrow = nrow(x), ncol = ncol(x)+pos)\r
+    \r
+    ## BSIZE contributed by Benno <puetz@mpipsykl.mpg.de> in e-mail\r
+    ## dated Wednesday, December 01, 2004\r
+    if (is.null(size) || !is.character(size)) {\r
+      BSIZE <- ""\r
+      ESIZE <- ""\r
+    } else {\r
+      if(length(grep("^\\\\", size)) == 0){\r
+        size <- paste("\\", size, sep = "")\r
+      }\r
+      ## Change suggested by Claudius Loehnert reported in Bug #6260\r
+      ## BSIZE <- paste("{", size, "\n", sep = "")\r
+      ## ESIZE <- "{\n"\r
+      BSIZE <- paste("\\begingroup", size, "\n", sep = "")\r
+      ESIZE <- "\\endgroup\n"\r
+    }\r
+    BLABEL <- "\\label{"\r
+    ELABEL <- "}\n"\r
+    ## Added caption width (jeff.laake@nooa.gov)\r
+    if(!is.null(caption.width)){\r
+      BCAPTION <- paste("\\parbox{",caption.width,"}{",sep="")\r
+      ECAPTION <- "}"\r
+    } else {\r
+      BCAPTION <- NULL\r
+      ECAPTION <- NULL\r
+    }\r
+    if (is.null(short.caption)){\r
+      BCAPTION <- paste(BCAPTION,"\\caption{",sep="")\r
+    } else {\r
+      BCAPTION <- paste(BCAPTION,"\\caption[", short.caption, "]{", sep="")\r
+    }\r
+    ECAPTION <- paste(ECAPTION,"} \n",sep="")\r
+    BROW <- ""\r
+    EROW <- " \\\\ \n"\r
+    BTH <- ""\r
+    ETH <- ""\r
+    STH <- " & "\r
+    BTD1 <- " & "\r
+    BTD2 <- ""\r
+    BTD3 <- ""\r
+    ETD  <- ""\r
+    } else {\r
+      BCOMMENT <- "<!-- "\r
+      ECOMMENT <- " -->\n"\r
+      BTABLE <- paste("<table ", html.table.attributes, ">\n", sep = "")\r
+      ETABLE <- "</table>\n"\r
+      BENVIRONMENT <- ""\r
+      EENVIRONMENT <- ""\r
+      BTABULAR <- ""\r
+      ETABULAR <- ""\r
+      BSIZE <- ""\r
+      ESIZE <- ""\r
+      BLABEL <- "<a name="\r
+      ELABEL <- "></a>\n"\r
+      BCAPTION <- paste("<caption align=\"", caption.placement, "\"> ",\r
+                        sep = "")\r
+      ECAPTION <- " </caption>\n"\r
+      BROW <- "<tr>"\r
+      EROW <- " </tr>\n"\r
+      BTH <- " <th> "\r
+      ETH <- " </th> "\r
+      STH <- " </th> <th> "\r
+      BTD1 <- " <td align=\""\r
+      align.tmp <- attr(x, "align", exact = TRUE)\r
+      align.tmp <- align.tmp[align.tmp!="|"]\r
+      if (nrow(x) == 0) {\r
+        BTD2 <- matrix(nrow = 0, ncol = ncol(x)+pos)\r
+      } else {\r
+        BTD2 <- matrix(align.tmp[(2-pos):(ncol(x)+1)],\r
+                       nrow = nrow(x), ncol = ncol(x)+pos, byrow = TRUE)\r
+      }\r
+      ## Based on contribution from Jonathan Swinton <jonathan@swintons.net>\r
+      ## in e-mail dated Wednesday, January 17, 2007\r
+      BTD2[regexpr("^p", BTD2)>0] <- "left"\r
+      BTD2[BTD2 == "r"] <- "right"\r
+      BTD2[BTD2 == "l"] <- "left"\r
+      BTD2[BTD2 == "c"] <- "center"\r
+      BTD3 <- "\"> "\r
+      ETD  <- " </td>"\r
+    }\r
+  \r
+  result <- string("", file = file, append = append)\r
+  info <- R.Version()\r
+  ## modified Claudio Agostinelli <claudio@unive.it> dated 2006-07-28\r
+  ## to set automatically the package version\r
+  if (comment){\r
+    result <- result + BCOMMENT + type + " table generated in " +\r
+      info$language + " " + info$major + "." + info$minor +\r
+      " by xtable " +  packageDescription('xtable')$Version +\r
+                                                  " package" + ECOMMENT\r
+    if (!is.null(timestamp)){\r
+      result <- result + BCOMMENT + timestamp + ECOMMENT\r
+    }\r
+  }\r
+  ## Claudio Agostinelli <claudio@unive.it> dated 2006-07-28 only.contents\r
+  if (!only.contents) {\r
+    result <- result + BTABLE\r
+    result <- result + BENVIRONMENT\r
+    if ( floating == TRUE ) {\r
+      if ((!is.null(caption)) &&\r
+          (type == "html" ||caption.placement == "top")) {\r
+        result <- result + BCAPTION + caption + ECAPTION\r
+      }\r
+      if (!is.null(attr(x, "label", exact = TRUE)) &&\r
+          (type == "latex" && caption.placement == "top")) {\r
+        result <- result + BLABEL +\r
+          attr(x, "label", exact = TRUE) + ELABEL\r
+      }\r
+    }\r
+    result <- result + BSIZE\r
+    result <- result + BTABULAR\r
+  }\r
+  ## Claudio Agostinelli <claudio@unive.it> dated 2006-07-28\r
+  ## include.colnames, include.rownames\r
+  if (include.colnames) {\r
+    COLNAMES <- string("", file = file, append = append)\r
+    COLNAMES <- COLNAMES + BROW + BTH\r
     if (include.rownames) {\r
-        ## David G. Whiting in e-mail 2007-10-09\r
-        if (is.null(sanitize.rownames.function)) {\r
-            RNAMES <- sanitize(row.names(x))\r
-        } else {\r
-            RNAMES <- sanitize.rownames.function(row.names(x))\r
-        }\r
-        if (rotate.rownames) {\r
-            ##added by Markus Loecher, 2009-11-16\r
-            RNAMES <- paste("\\begin{sideways}", RNAMES, "\\end{sideways}")\r
-       }\r
-       cols[, 1] <- RNAMES\r
+      COLNAMES <- COLNAMES + STH\r
     }\r
-\r
-## Begin vectorizing the formatting code by Ian Fellows [ian@fellstat.com]\r
-## 06 Dec 2011\r
-##\r
-##  disp <- function(y) {\r
-##    if (is.factor(y)) {\r
-##      y <- levels(y)[y]\r
-##    }\r
-##    if (is.list(y)) {\r
-##      y <- unlist(y)\r
-##    }\r
-##    return(y)\r
-##  }\r
-    varying.digits <- is.matrix( attr( x, "digits", exact = TRUE ) )\r
-    ## Code for letting "digits" be a matrix was provided by\r
-    ## Arne Henningsen <ahenningsen@agric-econ.uni-kiel.de>\r
-    ## in e-mail dated 2005-06-04.\r
-    ##if( !varying.digits ) {\r
-    ## modified Claudio Agostinelli <claudio@unive.it> dated 2006-07-28\r
-    ##  attr(x,"digits") <- matrix( attr( x, "digits",exact=TRUE ),\r
-    ## nrow = nrow(x), ncol = ncol(x)+1, byrow = TRUE )\r
-    ##}\r
-    for(i in 1:ncol(x)) {\r
-       xcol <- x[, i]\r
-       if(is.factor(xcol))\r
-            xcol <- as.character(xcol)\r
-       if(is.list(xcol))\r
-            xcol <- sapply(xcol, unlist)\r
-        ina <- is.na(xcol)\r
-        is.numeric.column <- is.numeric(xcol)\r
-\r
-       if(is.character(xcol)) {\r
-            cols[, i+pos] <- xcol\r
-       } else {\r
-            if (is.null(format.args)){\r
-                format.args <- list()\r
-            }\r
-            if (is.null(format.args$decimal.mark)){\r
-                format.args$decimal.mark <- options()$OutDec\r
-            }\r
-            if(!varying.digits){\r
-               curFormatArgs <-\r
-                    c(list(\r
-                      x = xcol,\r
-                      format =\r
-                      ifelse(attr(x, "digits", exact = TRUE )[i+1] < 0, "E",\r
-                                   attr(x, "display", exact = TRUE )[i+1]),\r
-                      digits = abs(attr(x, "digits", exact = TRUE )[i+1])),\r
-                      format.args)\r
-                cols[, i+pos] <- do.call("formatC", curFormatArgs)\r
-            }else{\r
-               for( j in 1:nrow( cols ) ) {\r
-                    curFormatArgs <-\r
-                        c(list(\r
-                          x = xcol[j],\r
-                          format =\r
-                          ifelse(attr(x, "digits", exact = TRUE )[j, i+1] < 0,\r
-                                 "E", attr(x, "display", exact = TRUE )[i+1]),\r
-                          digits =\r
-                          abs(attr(x, "digits", exact = TRUE )[j, i+1])),\r
-                          format.args)\r
-                    cols[j, i+pos] <- do.call("formatC", curFormatArgs)\r
-               }\r
+    ## David G. Whiting in e-mail 2007-10-09\r
+    if (is.null(sanitize.colnames.function)) {\r
+      CNAMES <- sanitize(names(x), type = type)\r
+    } else {\r
+      CNAMES <- sanitize.colnames.function(names(x))\r
+    }\r
+    if (rotate.colnames) {\r
+      ##added by Markus Loecher, 2009-11-16\r
+      CNAMES <- paste("\\begin{sideways}", CNAMES, "\\end{sideways}")\r
+    }\r
+    COLNAMES <- COLNAMES + paste(CNAMES, collapse = STH)\r
+    \r
+    COLNAMES <- COLNAMES + ETH + EROW\r
+    result <- result + COLNAMES\r
+    if (tabular.environment=="longtable") {\r
+        result <- result + "\\endfirsthead\n"\r
+        if (booktabs) {\r
+            if (!is.null(caption)) {\r
+                result <- result + "\\caption[]{"+caption+"} \\\\\n"\r
             }\r
-       }\r
-       ## End Ian Fellows changes\r
-\r
-        if ( any(ina) ) cols[ina, i+pos] <- NA.string\r
-        ## Based on contribution from Jonathan Swinton <jonathan@swintons.net>\r
-        ## in e-mail dated Wednesday, January 17, 2007\r
-        if ( is.numeric.column ) {\r
-            cols[, i+pos] <- sanitize.numbers(cols[, i+pos])\r
+            result <- result + "\\toprule\n"+ COLNAMES + "\\midrule\n\\endhead\n"\r
         } else {\r
-            if (is.null(sanitize.text.function)) {\r
-                cols[, i+pos] <- sanitize(cols[, i+pos])\r
-            } else {\r
-                cols[, i+pos] <- sanitize.text.function(cols[, i+pos])\r
+            if (!is.null(caption)) {\r
+                result <- result + "\\caption[]{"+caption+"}\n"\r
             }\r
+            result <- result + COLNAMES + "\\endhead\n"\r
         }\r
     }\r
-\r
-    multiplier <- 5\r
-    full <- matrix("", nrow = nrow(x), ncol = multiplier*(ncol(x)+pos)+2)\r
-    full[, 1] <- BROW\r
-    full[, multiplier*(0:(ncol(x)+pos-1))+2] <- BTD1\r
-    full[, multiplier*(0:(ncol(x)+pos-1))+3] <- BTD2\r
-    full[, multiplier*(0:(ncol(x)+pos-1))+4] <- BTD3\r
-    full[, multiplier*(0:(ncol(x)+pos-1))+5] <- cols\r
-    full[, multiplier*(0:(ncol(x)+pos-1))+6] <- ETD\r
-\r
-    full[, multiplier*(ncol(x)+pos)+2] <- paste(EROW, lastcol[-(1:2)],\r
-                                                sep = " ")\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
-            ## 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\r
-            ## 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(caption)) && (type == "latex")) {\r
-                    result <- result + BCAPTION + caption + ECAPTION\r
-                }\r
-            }\r
-            if (!is.null(attr(x, "label", exact = TRUE))) {\r
-                result <- result + BLABEL + attr(x, "label", exact = TRUE) +\r
-                    ELABEL\r
-            }\r
-            ETABULAR <- "\\end{longtable}\n"\r
+  }\r
+  cols <- matrix("", nrow = nrow(x), ncol = ncol(x)+pos)\r
+  if (include.rownames) {\r
+    ## David G. Whiting in e-mail 2007-10-09\r
+    if (is.null(sanitize.rownames.function)) {\r
+      RNAMES <- sanitize(row.names(x), type = type)\r
+    } else {\r
+      RNAMES <- sanitize.rownames.function(row.names(x))\r
+    }\r
+    if (rotate.rownames) {\r
+      ##added by Markus Loecher, 2009-11-16\r
+      RNAMES <- paste("\\begin{sideways}", RNAMES, "\\end{sideways}")\r
+    }\r
+    cols[, 1] <- RNAMES\r
+  }\r
+\r
+  ## Begin vectorizing the formatting code by Ian Fellows [ian@fellstat.com]\r
+  ## 06 Dec 2011\r
+  ##\r
+  ##  disp <- function(y) {\r
+  ##    if (is.factor(y)) {\r
+  ##      y <- levels(y)[y]\r
+  ##    }\r
+  ##    if (is.list(y)) {\r
+  ##      y <- unlist(y)\r
+  ##    }\r
+  ##    return(y)\r
+  ##  }\r
+  varying.digits <- is.matrix( attr( x, "digits", exact = TRUE ) )\r
+  ## Code for letting "digits" be a matrix was provided by\r
+  ## Arne Henningsen <ahenningsen@agric-econ.uni-kiel.de>\r
+  ## in e-mail dated 2005-06-04.\r
+  ##if( !varying.digits ) {\r
+  ## modified Claudio Agostinelli <claudio@unive.it> dated 2006-07-28\r
+  ##  attr(x,"digits") <- matrix( attr( x, "digits",exact=TRUE ),\r
+  ## nrow = nrow(x), ncol = ncol(x)+1, byrow = TRUE )\r
+  ##}\r
+  for(i in 1:ncol(x)) {\r
+    xcol <- x[, i]\r
+    if(is.factor(xcol))\r
+      xcol <- as.character(xcol)\r
+    if(is.list(xcol))\r
+      xcol <- sapply(xcol, unlist)\r
+    ina <- is.na(xcol)\r
+    is.numeric.column <- is.numeric(xcol)\r
+    \r
+    if(is.character(xcol)) {\r
+      cols[, i+pos] <- xcol\r
+    } else {\r
+      if (is.null(format.args)){\r
+        format.args <- list()\r
+      }\r
+      if (is.null(format.args$decimal.mark)){\r
+        format.args$decimal.mark <- options()$OutDec\r
+      }\r
+      if(!varying.digits){\r
+        curFormatArgs <-\r
+          c(list(\r
+            x = xcol,\r
+            format =\r
+              ifelse(attr(x, "digits", exact = TRUE )[i+1] < 0, "E",\r
+                     attr(x, "display", exact = TRUE )[i+1]),\r
+            digits = abs(attr(x, "digits", exact = TRUE )[i+1])),\r
+            format.args)\r
+        cols[, i+pos] <- do.call("formatC", curFormatArgs)\r
+      }else{\r
+        for( j in 1:nrow( cols ) ) {\r
+          curFormatArgs <-\r
+            c(list(\r
+              x = xcol[j],\r
+              format =\r
+                ifelse(attr(x, "digits", exact = TRUE )[j, i+1] < 0,\r
+                       "E", attr(x, "display", exact = TRUE )[i+1]),\r
+              digits =\r
+                abs(attr(x, "digits", exact = TRUE )[j, i+1])),\r
+              format.args)\r
+          cols[j, i+pos] <- do.call("formatC", curFormatArgs)\r
         }\r
-        result <- result + ETABULAR\r
-        result <- result + ESIZE\r
-        if ( floating == TRUE ) {\r
-            if ((!is.null(caption)) &&\r
-                (type == "latex" && caption.placement == "bottom")) {\r
-                result <- result + BCAPTION + caption + ECAPTION\r
-            }\r
-            if (!is.null(attr(x, "label", exact = TRUE)) &&\r
-                caption.placement == "bottom") {\r
-                result <- result + BLABEL + attr(x, "label", exact = TRUE) +\r
-                    ELABEL\r
-            }\r
+      }\r
+    }\r
+    ## End Ian Fellows changes\r
+\r
+    if ( any(ina) ) cols[ina, i+pos] <- NA.string\r
+    ## Based on contribution from Jonathan Swinton <jonathan@swintons.net>\r
+    ## in e-mail dated Wednesday, January 17, 2007\r
+    if ( is.numeric.column ) {\r
+      cols[, i+pos] <-\r
+        sanitize.numbers(cols[, i+pos], type = type,\r
+                         math.style.negative = math.style.negative,\r
+                         math.style.exponents = math.style.exponents)\r
+    } else {\r
+      if (is.null(sanitize.text.function)) {\r
+        cols[, i+pos] <- sanitize(cols[, i+pos], type = type)\r
+      } else {\r
+        cols[, i+pos] <- sanitize.text.function(cols[, i+pos])\r
+      }\r
+    }\r
+  }\r
+  \r
+  multiplier <- 5\r
+  full <- matrix("", nrow = nrow(x), ncol = multiplier*(ncol(x)+pos)+2)\r
+  full[, 1] <- BROW\r
+  full[, multiplier*(0:(ncol(x)+pos-1))+2] <- BTD1\r
+  full[, multiplier*(0:(ncol(x)+pos-1))+3] <- BTD2\r
+  full[, multiplier*(0:(ncol(x)+pos-1))+4] <- BTD3\r
+  full[, multiplier*(0:(ncol(x)+pos-1))+5] <- cols\r
+  full[, multiplier*(0:(ncol(x)+pos-1))+6] <- ETD\r
+  \r
+  full[, multiplier*(ncol(x)+pos)+2] <- paste(EROW, lastcol[-(1:2)],\r
+                                              sep = " ")\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
+      ## 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\r
+      ## 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(caption)) && (type == "latex")) {\r
+          result <- result + BCAPTION + caption + ECAPTION\r
         }\r
-        result <- result + EENVIRONMENT\r
-        result <- result + ETABLE\r
+      }\r
+      if (!is.null(attr(x, "label", exact = TRUE))) {\r
+        result <- result + BLABEL + attr(x, "label", exact = TRUE) +\r
+          ELABEL\r
+      }\r
+      ETABULAR <- "\\end{longtable}\n"\r
     }\r
-    result <- sanitize.final(result)\r
-\r
-    if (print.results){\r
-       print(result)\r
+    result <- result + ETABULAR\r
+    result <- result + ESIZE\r
+    if ( floating == TRUE ) {\r
+      if ((!is.null(caption)) &&\r
+          (type == "latex" && caption.placement == "bottom")) {\r
+        result <- result + BCAPTION + caption + ECAPTION\r
+      }\r
+      if (!is.null(attr(x, "label", exact = TRUE)) &&\r
+          caption.placement == "bottom") {\r
+        result <- result + BLABEL + attr(x, "label", exact = TRUE) +\r
+          ELABEL\r
+      }\r
     }\r
-\r
-    return(invisible(result$text))\r
+    result <- result + EENVIRONMENT\r
+    result <- result + ETABLE\r
+  }\r
+  result <- sanitize.final(result, type = type)\r
+  \r
+  if (print.results){\r
+    print(result)\r
+  }\r
+  \r
+  return(invisible(result$text))\r
 }\r
 \r
 "+.string" <- function(x, y) {\r
-    x$text <- paste(x$text, as.string(y)$text, sep = "")\r
-    return(x)\r
+  x$text <- paste(x$text, as.string(y)$text, sep = "")\r
+  return(x)\r
 }\r
 \r
 print.string <- function(x, ...) {\r
-    cat(x$text, file = x$file, append = x$append)\r
-    return(invisible())\r
+  cat(x$text, file = x$file, append = x$append)\r
+  return(invisible())\r
 }\r
 \r
 string <- function(text, file = "", append = FALSE) {\r
-    x <- list(text = text, file = file, append = append)\r
-    class(x) <- "string"\r
-    return(x)\r
+  x <- list(text = text, file = file, append = append)\r
+  class(x) <- "string"\r
+  return(x)\r
 }\r
 \r
 as.string <- function(x, file = "", append = FALSE) {\r
-    if (is.null(attr(x, "class", exact = TRUE)))\r
-        switch(data.class(x),\r
-               character = return(string(x, file, append)),\r
-               numeric = return(string(as.character(x), file, append)),\r
-               stop("Cannot coerce argument to a string"))\r
-    if (class(x) == "string")\r
-        return(x)\r
-    stop("Cannot coerce argument to a string")\r
+  if (is.null(attr(x, "class", exact = TRUE)))\r
+    switch(data.class(x),\r
+           character = return(string(x, file, append)),\r
+           numeric = return(string(as.character(x), file, append)),\r
+           stop("Cannot coerce argument to a string"))\r
+  if (class(x) == "string")\r
+    return(x)\r
+  stop("Cannot coerce argument to a string")\r
 }\r
 \r
 is.string <- function(x) {\r
-    return(class(x) == "string")\r
+  return(class(x) == "string")\r
 }\r
 \r
diff --git a/pkg/R/sanitize.R b/pkg/R/sanitize.R
new file mode 100644 (file)
index 0000000..77404b7
--- /dev/null
@@ -0,0 +1,97 @@
+sanitize <- function(str, type = "latex") {
+  if(type == "latex"){
+    result <- str
+    result <- gsub("\\\\", "SANITIZE.BACKSLASH", result)
+    result <- gsub("$", "\\$", result, fixed = TRUE)
+    result <- gsub(">", "$>$", result, fixed = TRUE)
+    result <- gsub("<", "$<$", result, fixed = TRUE)
+    result <- gsub("|", "$|$", result, fixed = TRUE)
+    result <- gsub("{", "\\{", result, fixed = TRUE)
+    result <- gsub("}", "\\}", result, fixed = TRUE)
+    result <- gsub("%", "\\%", result, fixed = TRUE)
+    result <- gsub("&", "\\&", result, fixed = TRUE)
+    result <- gsub("_", "\\_", result, fixed = TRUE)
+    result <- gsub("#", "\\#", result, fixed = TRUE)
+    result <- gsub("^", "\\verb|^|", result, fixed = TRUE)
+    result <- gsub("~", "\\~{}", result, fixed = TRUE)
+    result <- gsub("SANITIZE.BACKSLASH", "$\\backslash$", result, fixed = TRUE)
+    return(result)
+  } else {
+    result <- str
+    result <- gsub("&", "&amp;", result, fixed = TRUE)
+    result <- gsub(">", "&gt;", result, fixed = TRUE)
+    result <- gsub("<", "&lt;", result, fixed = TRUE)
+    return(result)
+  }
+}
+
+
+sanitize.numbers <- function(str, type,
+                             math.style.negative = FALSE,
+                             math.style.exponents = FALSE){
+  if (type == "latex"){
+    result <- str
+    if ( math.style.negative ) {
+      for(i in 1:length(str)) {
+        result[i] <- gsub("-", "$-$", result[i], fixed = TRUE)
+      }
+    }
+    if ( math.style.exponents ) {
+      if (is.logical(math.style.exponents) && ! math.style.exponents ) {
+      } else if (is.logical(math.style.exponents) && math.style.exponents ||
+                 math.style.exponents == "$$"
+                 ) {
+        for(i in 1:length(str)) {
+          result[i] <-
+            gsub("^\\$?(-?)\\$?([0-9.]+)[eE]\\$?(-?)\\+?\\$?0*(\\d+)$",
+                 "$\\1\\2 \\\\times 10^{\\3\\4}$", result[i])
+        }
+      } else if (math.style.exponents == "ensuremath") {
+        for(i in 1:length(str)) {
+          result[i] <-
+            gsub("^\\$?(-?)\\$?([0-9.]+)[eE]\\$?(-?)\\+?\\$?0*(\\d+)$",
+                 "\\\\ensuremath{\\1\\2 \\\\times 10^{\\3\\4}}",
+                 result[i])
+        }
+      } else if (math.style.exponents == "UTF8" ||
+                 math.style.exponents == "UTF-8") {
+        for(i in 1:length(str)) {
+          ## this code turns 1e5 into a UTF-8 representation of 1\times10^5
+          if (all(grepl("^\\$?(-?)\\$?([0-9.]+)[eE]\\$?(-?)\\+?\\$?0*(\\d+)$",
+                        result[i]))) {
+            temp <- strsplit(result[i],"eE",result[i])
+            result[i] <-
+              paste0(temp[1],
+                     "\u00d710",
+                     chartr("-1234567890",
+                            "\u207b\u00b9\u00b2\u00b3\u2074\u2075\u20746\u20747\u20748\u20749\u2070",
+                            temp[2]))
+          }
+        }
+      }
+    }
+    return(result)
+  } else {
+    return(str)
+  }
+}
+
+
+sanitize.final <- function(str, type){
+  if (type == "latex"){
+    return(str)
+  } else {
+    str$text <- gsub("  *", " ",  str$text, fixed = TRUE)
+    str$text <- gsub(' align="left"',  "", str$text,
+                     fixed = TRUE)
+    return(str)
+  }
+}
+
+### Some trivial helper functions
+### Suggested by Stefan Edwards, sme@iysik.com
+### Helper function for disabling sanitizing
+as.is <- function(str) {str}
+
+### Helper function for embedding names in a math environment
+as.math <- function(str, ...) { paste0('$',str,'$', ...) }
index 718e41fc958a19b956c132ff7b4236014cdaf0d2..9932cef15485e6c66b4ee35a97e117875f990ff7 100644 (file)
 ### Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 ### MA 02111-1307, USA
 
-"caption<-" <- function(x,value) UseMethod("caption<-")
-"caption<-.xtable" <- function(x,value) {
-  if (length(value)>2)
+"caption<-" <- function(x, value) UseMethod("caption<-")
+"caption<-.xtable" <- function(x, value) {
+  if (length(value) > 2)
     stop("\"caption\" must have length 1 or 2")
-  attr(x,"caption") <- value
+  attr(x, "caption") <- value
   return(x)
 }
 
-caption <- function(x,...) UseMethod("caption")
-caption.xtable <- function(x,...) {
-  return(attr(x,"caption",exact=TRUE))
+caption <- function(x, ...) UseMethod("caption")
+caption.xtable <- function(x, ...) {
+  return(attr(x, "caption", exact = TRUE))
 }
 
-"label<-" <- function(x,value) UseMethod("label<-")
-"label<-.xtable" <- function(x,value) {
-  if (length(value)>1)
+"label<-" <- function(x, value) UseMethod("label<-")
+"label<-.xtable" <- function(x, value) {
+  if (length(value) > 1)
     stop("\"label\" must have length 1")
-  attr(x,"label") <- value
+  attr(x, "label") <- value
   return(x)
 }
 
-label <- function(x,...) UseMethod("label")
-label.xtable <- function(x,...) {
-  return(attr(x,"label",exact=TRUE))
+label <- function(x, ...) UseMethod("label")
+label.xtable <- function(x, ...) {
+  return(attr(x, "label", exact = TRUE))
 }
 
-"align<-" <- function(x,value) UseMethod("align<-")
+"align<-" <- function(x, value) UseMethod("align<-")
 
-# Based on contribution from Jonathan Swinton <jonathan@swintons.net> in e-mail dated Wednesday, January 17, 2007
+### Based on contribution from Jonathan Swinton <jonathan@swintons.net>
+### in e-mail dated Wednesday, January 17, 2007
 .alignStringToVector <- function(aString) {
-  # poor mans parsing - separating string of form "l{2in}llr|p{1in}c|{1in}"
-  # into "l{2in}" "l"      "l"      "r"      "|"      "p{1in}" "c"      "|{1in}"
+  ## poor mans parsing - separating string of form "l{2in}llr|p{1in}c|{1in}"
+  ## into "l{2in}" "l"  "l"  "r" "|" "p{1in}" "c" "|{1in}"
   aString.Align <- character(0);
   aString.Width <- character(0);
   wString <- aString
-  while( nchar(wString)>0) {
-    aString.Align <- c(aString.Align,substr(wString,1,1))
-    # is it followed by a brace?
+  while( nchar(wString) > 0) {
+    aString.Align <- c(aString.Align, substr(wString, 1, 1))
+    ## is it followed by a brace?
     thisWidth <- ""
-    if ( nchar(wString)>1 & substr(wString,2,2)=="{") {
-      beforeNextBrace <- regexpr("[^\\]\\}",wString)
+    if ( nchar(wString) > 1 & substr(wString, 2, 2) == "{") {
+      beforeNextBrace <- regexpr("[^\\]\\}", wString)
       if (beforeNextBrace <0 ) {
         stop("No closing } in align string")
       }
-      thisWidth <- substr(wString,2,beforeNextBrace+1)
-      wString <- substr(wString,beforeNextBrace+2,nchar(wString))
+      thisWidth <- substr(wString, 2, beforeNextBrace + 1)
+      wString <- substr(wString, beforeNextBrace + 2, nchar(wString))
     } else {
-      wString <- substr(wString,2,nchar(wString))
+      wString <- substr(wString, 2, nchar(wString))
     }
-    aString.Width <- c(aString.Width,thisWidth)
+    aString.Width <- c(aString.Width, thisWidth)
   }
 
   alignAllowed <- c("l","r","p","c","|","X")
@@ -77,78 +78,84 @@ label.xtable <- function(x,...) {
   if (any( !(aString.Align %in% alignAllowed))) {
     warning("Nonstandard alignments in align string")
   }
-  res <- paste(aString.Align,aString.Width,sep="")
+  res <- paste(aString.Align, aString.Width, sep = "")
   res
 }
-#.alignStringToVector ("l{2in}llr|p{1in}c|{1in}")
-#.alignStringToVector ("l{2in}llr|p{1in}c|")
-#.alignStringToVector ("{2in}llr|p{1in}c|") # latex syntax error, but gives wrong alignment
-#.alignStringToVector("llllp{3cm}")
-
-"align<-.xtable" <- function(x,value) {
-# Based on contribution from Benno <puetz@mpipsykl.mpg.de> in e-mail dated Wednesday, December 01, 2004
-# Based on contribution from Jonathan Swinton <jonathan@swintons.net> in e-mail dated Wednesday, January 17, 2007
-  # cat("%",value,"\n")
-  if ( (!is.null(value)) && ( is.character(value) ) && ( length(value) == 1 ) && ( nchar(value) > 1 ) ) {
+###.alignStringToVector ("l{2in}llr|p{1in}c|{1in}")
+###.alignStringToVector ("l{2in}llr|p{1in}c|")
+### latex syntax error, but gives wrong alignment
+###.alignStringToVector ("{2in}llr|p{1in}c|")
+###.alignStringToVector("llllp{3cm}")
+
+"align<-.xtable" <- function(x, value) {
+### Based on contribution from Benno <puetz@mpipsykl.mpg.de>
+### in e-mail dated Wednesday, December 01, 2004
+### Based on contribution from Jonathan Swinton <jonathan@swintons.net>
+### in e-mail dated Wednesday, January 17, 2007
+  ## cat("%", value, "\n")
+  if ( (!is.null(value)) && ( is.character(value) ) &&
+       ( length(value) == 1 ) && ( nchar(value) > 1 ) ) {
         value <- .alignStringToVector(value)
-  } # That should have checked we had only lrcp|
-    # but what if the "if statement" is false?
-    # For simplicity, deleting check present in version 1.4-2 and earlier.
-  c.value <- if (any(!is.na(match(value,"|")))) {
-                value[-which(value=='|')]
+  }
+  ## That should have checked we had only lrcp|
+  ## but what if the "if statement" is false?
+  ## For simplicity, deleting check present in version 1.4-2 and earlier.
+  c.value <- if (any(!is.na(match(value, "|")))) {
+               value[-which(value == '|')]
              } else {
-                value
+               value
              }
-  if (length(c.value)!=ncol(x)+1)
-      stop(paste("\"align\" must have length equal to",ncol(x)+1,"( ncol(x) + 1 )"))
-
-  attr(x,"align") <- value
+  if (length(c.value) != ncol(x) + 1)
+    stop(paste("\"align\" must have length equal to",
+               ncol(x) + 1, "( ncol(x) + 1 )"))
+  attr(x, "align") <- value
   return(x)
 }
 
-align <- function(x,...) UseMethod("align")
-align.xtable <- function(x,...) {
-  return(attr(x,"align",exact=TRUE))
+align <- function(x, ...) UseMethod("align")
+align.xtable <- function(x, ...) {
+  return(attr(x, "align", exact = TRUE))
 }
 
-"digits<-" <- function(x,value) UseMethod("digits<-")
-"digits<-.xtable" <- function(x,value) {
+"digits<-" <- function(x, value) UseMethod("digits<-")
+"digits<-.xtable" <- function(x, value) {
   if( is.matrix( value ) ) {
-    if( ncol( value ) != ncol(x)+1 || nrow( value ) != nrow(x) ) {
+    if( ncol( value ) != ncol(x) + 1 || nrow( value ) != nrow(x) ) {
       stop( "if argument 'digits' is a matrix, it must have columns equal",
-        " to ", ncol(x)+1, " ( ncol(x) + 1 ) and rows equal to ", nrow(x),
-        " ( nrow( x )" )
+           " to ", ncol(x) + 1, " ( ncol(x) + 1 ) and rows equal to ", nrow(x),
+           " ( nrow( x )" )
     }
   } else {
-    if( length(value)==1 ) { value <- rep(value, ncol(x)+1) }
-    if( length( value ) >1 & length( value ) != ncol(x)+1 ) {
+    if( length(value) == 1 ) { value <- rep(value, ncol(x) + 1) }
+    if( length( value ) > 1 & length( value ) != ncol(x) + 1 ) {
       stop( "if argument 'digits' is a vector of length more than one, it must have length equal",
-        " to ", ncol(x)+1, " ( ncol(x) + 1 )" )
+           " to ", ncol(x) + 1, " ( ncol(x) + 1 )" )
     }
   }
   if (!is.numeric(value))
     stop("\"digits\" must be numeric")
-  attr(x,"digits") <- value
+  attr(x, "digits") <- value
   return(x)
 }
 
-digits <- function(x,...) UseMethod("digits")
-digits.xtable <- function(x,...) {
-  return(attr(x,"digits",exact=TRUE))
+digits <- function(x, ...) UseMethod("digits")
+digits.xtable <- function(x, ...) {
+  return(attr(x, "digits", exact = TRUE))
 }
 
-"display<-" <- function(x,value) UseMethod("display<-")
-"display<-.xtable" <- function(x,value) {
-  if (length(value)!=ncol(x)+1)
-    stop(paste("\"display\" must have length equal to",ncol(x)+1,"( ncol(x) + 1 )"))
-  if (!all(!is.na(match(value,c("d","f","e","E","g","G","fg","s")))))
+"display<-" <- function(x, value) UseMethod("display<-")
+"display<-.xtable" <- function(x, value) {
+  if (length(value) != ncol(x) + 1)
+    stop(paste("\"display\" must have length equal to",
+               ncol(x) + 1, "( ncol(x) + 1 )"))
+  if (!all(!is.na(match(value, c("d","f","e","E","g","G","fg","s")))))
     stop("\"display\" must be in {\"d\",\"f\",\"e\",\"E\",\"g\",\"G\", \"fg\", \"s\"}")
-  attr(x,"display") <- value
+  attr(x, "display") <- value
   return(x)
 }
 
-display <- function(x,...) UseMethod("display")
-display.xtable <- function(x,...) {
-  return(attr(x,"display",exact=TRUE))
+display <- function(x, ...) UseMethod("display")
+display.xtable <- function(x, ...) {
+  return(attr(x, "display", exact = TRUE))
 }
 
index 854e6e36528fb0b8f6ff5863b767bf7d0c445900..86fada2cf361df0749099d6e1e54dde9e080fc86 100644 (file)
 ### 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
index 011179d3feaf7cc6412cbb1c13872dde3cdb2fa2..c2380df5a3fc28063d01d8d37c209a39ef110cf4 100644 (file)
@@ -26,7 +26,7 @@ xtable <- function(x, caption = NULL, label = NULL, align = NULL,
 }
 
 
-## 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,
@@ -63,10 +63,12 @@ xtable.matrix <- function(x, caption = NULL, label = NULL, align = NULL,
                           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,
+                           ...))
 }
 
 
+
 ### table objects (of 1 or 2 dimensions) by Guido Gay, 9 Feb 2007
 ### Fixed to pass R checks by DBD, 9 May 2007
 xtable.table <- function(x, caption = NULL, label = NULL, align = NULL,
@@ -76,20 +78,19 @@ xtable.table <- function(x, caption = NULL, label = NULL, align = NULL,
                                 dimnames = list(rownames(x),
                                                 names(dimnames(x)))),
                          caption = caption, label = label, align = align,
-                         digits = digits, display = display, auto = auto))
+                         digits = digits, display = display, auto = auto, ...))
   } else if (length(dim(x))==2) {
     return(xtable.matrix(matrix(x, ncol = dim(x)[2], nrow = dim(x)[1],
                                 dimnames = list(rownames(x), colnames(x))),
                          caption = caption, label = label, align = align,
-                         digits = digits, display = display, auto = auto))
+                         digits = digits, display = display, auto = auto, ...))
   } else {
     stop("xtable.table is not implemented for tables of > 2 dimensions")
   }
 }
 
 
-## anova objects
-
+### anova objects
 xtable.anova <- function(x, caption = NULL, label = NULL, align = NULL,
                          digits = NULL, display = NULL, auto = FALSE, ...) {
   suggested.digits <- c(0,rep(2, ncol(x)))
@@ -110,20 +111,19 @@ xtable.anova <- function(x, caption = NULL, label = NULL, align = NULL,
 }
 
 
-## aov objects
-
+### aov objects
 xtable.aov <- function(x, caption = NULL, label = NULL, align = NULL,
                        digits = NULL, display = NULL, auto = FALSE, ...) {
   return(xtable.anova(anova(x, ...), caption = caption, label = label,
                       align = align, digits = digits, display = display,
-                      auto = auto))
+                      auto = auto, ...))
 }
 
 xtable.summary.aov <- function(x, caption = NULL, label = NULL, align = NULL,
                                digits = NULL, display = NULL, auto = FALSE,
                                ...) {
   return(xtable.anova(x[[1]], caption = caption, label = label, align = align,
-                      digits = digits, display = display, auto = auto))
+                      digits = digits, display = display, auto = auto, ...))
 }
 
 xtable.summary.aovlist <- function(x, caption = NULL, label = NULL,
@@ -134,13 +134,13 @@ xtable.summary.aovlist <- function(x, caption = NULL, label = NULL,
             result <- xtable.summary.aov(x[[i]], caption = caption,
                                          label = label,
                                          align = align, digits = digits,
-                                         display = display, auto = auto)
+                                         display = display, auto = auto, ...)
         } else {
             result <- rbind(result,
                             xtable.anova(x[[i]][[1]], caption = caption,
                                          label = label, align = align,
                                          digits = digits, display = display,
-                                         auto = auto))
+                                         auto = auto, ...))
         }
     }
     return(result)
@@ -150,18 +150,17 @@ xtable.aovlist <- function(x, caption = NULL, label = NULL, align = NULL,
                            digits = NULL, display = NULL, auto = FALSE, ...) {
   return(xtable.summary.aovlist(summary(x), caption = caption, label = label,
                                 align = align, digits = digits,
-                                display = display, auto = auto))
+                                display = display, auto = auto, ...))
 }
 
 
 
-## lm objects
-
+### lm objects
 xtable.lm <- function(x, caption = NULL, label = NULL, align = NULL,
                       digits = NULL, display = NULL, auto = FALSE, ...) {
   return(xtable.summary.lm(summary(x), caption = caption, label = label,
                            align = align, digits = digits, display = display,
-                           auto = auto))
+                           auto = auto, ...))
 }
 
 xtable.summary.lm <- function(x, caption = NULL, label = NULL, align = NULL,
@@ -182,25 +181,25 @@ xtable.summary.lm <- function(x, caption = NULL, label = NULL, align = NULL,
 }
 
 
-## glm objects
-
+### glm objects
 xtable.glm <- function(x, caption = NULL, label = NULL, align = NULL,
                        digits = NULL, display = NULL, auto = FALSE, ...) {
   return(xtable.summary.glm(summary(x), caption = caption,
                             label = label, align = align,
-                            digits = digits, display = display, auto = auto))
+                            digits = digits, display = display,
+                            auto = auto, ...))
 }
 
 xtable.summary.glm <- function(x, caption = NULL, label = NULL, align = NULL,
                                digits = NULL, display = NULL, auto = FALSE,
                                ...) {
   return(xtable.summary.lm(x, caption = caption, label = label, align = align,
-                           digits = digits, display = display, auto = auto))
+                           digits = digits, display = display,
+                           auto = auto, ...))
 }
 
 
-## prcomp objects
-
+### prcomp objects
 xtable.prcomp <- function(x, caption = NULL, label = NULL, align = NULL,
                           digits = NULL, display = NULL, auto = FALSE, ...) {
   x <- data.frame(x$rotation, check.names = FALSE)
@@ -235,10 +234,10 @@ xtable.summary.prcomp <- function(x, caption = NULL, label = NULL, align = NULL,
 }
 
 
-# Slightly modified version of xtable.coxph contributed on r-help by
-#   Date: Wed, 2 Oct 2002 17:47:56 -0500 (CDT)
-#   From: Jun Yan <jyan@stat.wisc.edu>
-#   Subject: Re: [R] xtable for Cox model output
+### Slightly modified version of xtable.coxph contributed on r-help by
+###   Date: Wed, 2 Oct 2002 17:47:56 -0500 (CDT)
+###   From: Jun Yan <jyan@stat.wisc.edu>
+###   Subject: Re: [R] xtable for Cox model output
 xtable.coxph <- function (x, caption = NULL, label = NULL, align = NULL,
                           digits = NULL, display = NULL, auto = FALSE, ...)
 {
@@ -249,24 +248,23 @@ xtable.coxph <- function (x, caption = NULL, label = NULL, align = NULL,
     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),
       c("coef", "exp(coef)", "robust se", "z", "p"))
   }
   return(xtable(tmp, caption = caption, label = label, align = align,
-                digits = digits, display = display, auto = auto))
+                digits = digits, display = display, auto = auto, ...))
 }
 
-# Additional method: xtable.ts
-# Contributed by David Mitchell (davidm@netspeed.com.au)
-# Date: July 2003
+### Additional method: xtable.ts
+### Contributed by David Mitchell (davidm@netspeed.com.au)
+### Date: July 2003
 xtable.ts <- function(x, caption = NULL, label = NULL, align = NULL,
                       digits = NULL, display = NULL, auto = FALSE, ...) {
   if (inherits(x, "ts") && !is.null(ncol(x))) {
-    # COLNAMES <- paste(colnames(x));
+    ## COLNAMES <- paste(colnames(x));
     tp.1 <- trunc(time(x))
     tp.2 <- trunc(cycle(x))
     day.abb <- c("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
@@ -279,8 +277,7 @@ xtable.ts <- function(x, caption = NULL, label = NULL, align = NULL,
                        "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
@@ -297,11 +294,157 @@ xtable.ts <- function(x, caption = NULL, label = NULL, align = NULL,
     names(tmp) <- COLNAMES
   }
   return(xtable(tmp, caption = caption, label = label, align = align,
-                digits = digits, display = display, auto = auto))
+                digits = digits, display = display, auto = auto, ...))
+}
+
+### Suggested by Ajay Narottam Shah <ajayshah@mayin.org> in e-mail 2006/07/22
+xtable.zoo <- function(x, caption = NULL, label = NULL, align = NULL,
+                       digits = NULL, display = NULL, auto = FALSE, ...) {
+  return(xtable(as.ts(x), caption = caption, label = label,
+                align = align, digits = digits,
+                display = display, auto = auto, ...))
+}
+
+### Date: Fri, 29 May 2015 11:41:04 +0200
+### From: Martin G. <martin.gubri@framasoft.org>
+### Subject: [xtable] Code for spdep, splm and sphet objects outputs
+### package spdep
+### sarlm objects
+xtable.sarlm <- function(x, caption = NULL, label = NULL, align = NULL,
+                         digits = NULL, display = NULL, auto = FALSE, ...) {
+  return(xtable.summary.sarlm(summary(x), caption = caption, label = label,
+                              align = align, digits = digits,
+                              display = display, auto = auto, ...))
+}
+
+xtable.summary.sarlm <- function(x, caption = NULL, label = NULL, align = NULL,
+                                digits = NULL, display = NULL, auto = FALSE,
+                                ...) {
+  x <- data.frame(x$Coef, check.names = FALSE)
+
+  class(x) <- c("xtable","data.frame")
+  caption(x) <- caption
+  label(x) <- label
+  if(auto && is.null(align))   align   <- xalign(x)
+  if(auto && is.null(digits))  digits  <- xdigits(x)
+  if(auto && is.null(display)) display <- xdisplay(x)
+  align(x) <- switch(1+is.null(align), align, c("r","r","r","r","r"))
+  digits(x) <- switch(1+is.null(digits), digits, c(0,4,4,2,4))
+  display(x) <- switch(1+is.null(display), display, c("s","f","f","f","f"))
+  return(x)
+}
+
+### spautolm objects: added by David Scott, 6/1/2016, after suggestion by
+### Guido Schulz
+### Date: Wed, 29 Apr 2015 10:45:16 +0200
+### Guido Schulz <schulzgu@student.hu-berlin.de>
+xtable.spautolm <- function(x, caption = NULL, label = NULL, align = NULL,
+                            digits = NULL, display = NULL, auto = FALSE, ...) {
+    return(xtable.summary.sarlm(summary(x), caption = caption, label = label,
+                              align = align, digits = digits,
+                              display = display, auto = auto, ...))
+}
+
+xtable.summary.spautolm <- function(x, caption = NULL, label = NULL,
+                                    align = NULL, digits = NULL,
+                                    display = NULL, auto = FALSE, ...) {
+    return(xtable.summary.sarlm(summary(x), caption = caption, label = label,
+                              align = align, digits = digits,
+                              display = display, auto = auto, ...))
 }
 
-# Suggested by Ajay Narottam Shah <ajayshah@mayin.org> in e-mail 2006/07/22
-xtable.zoo <- function(x, ...) {
-  return(xtable(as.ts(x), ...))
+
+### gmsar objects
+xtable.gmsar <- function(x, caption = NULL, label = NULL, align = NULL,
+                         digits = NULL, display = NULL, auto = FALSE, ...) {
+    return(xtable.summary.sarlm(summary(x), caption = caption, label = label,
+                              align = align, digits = digits,
+                              display = display, auto = auto, ...))
+}
+
+xtable.summary.gmsar <- function(x, caption = NULL, label = NULL, align = NULL,
+                                 digits = NULL, display = NULL,
+                                 auto = FALSE, ...) {
+  return(xtable.summary.sarlm(x, caption = caption, label = label,
+                              align = align, digits = digits,
+                              display = display, auto = auto, ...))
+}
+
+### stsls objects
+xtable.stsls <- function(x, caption = NULL, label = NULL, align = NULL,
+                         digits = NULL, display = NULL, auto = FALSE, ...) {
+  return(xtable.summary.sarlm(summary(x), caption = caption, label = label,
+                              align = align, digits = digits,
+                              display = display, auto = auto, ...))
+}
+
+xtable.summary.stsls <- function(x, caption = NULL, label = NULL, align = NULL,
+                                 digits = NULL, display = NULL,
+                                 auto = FALSE, ...) {
+  return(xtable.summary.sarlm(x, caption = caption, label = label,
+                              align = align, digits = digits,
+                              display = display, auto = auto, ...))
+}
+
+### pred.sarlm objects
+xtable.sarlm.pred <- function(x, caption = NULL, label = NULL, align = NULL,
+                              digits = NULL, display = NULL,
+                              auto = FALSE, ...) {
+  return(xtable(as.data.frame(x), caption = caption, label = label,
+                align = align, digits = digits,
+                display = display, auto = auto, ...))
+}
+
+### lagImpact objects
+xtable.lagImpact <- function(x, caption = NULL, label = NULL, align = NULL,
+                             digits = NULL, display = NULL,
+                             auto = FALSE, ...) {
+  requireNamespace('spdep')
+  lagImpactMat <- get('lagImpactMat', environment(spdep::spdep))
+  xtable(lagImpactMat(x), caption = caption, label = label,
+         align = align, digits = digits,
+         display = display, auto = auto, ...)
+}
+
+### package splm
+### splm objects
+xtable.splm <- function(x, caption = NULL, label = NULL, align = NULL,
+                        digits = NULL, display = NULL, auto = FALSE, ...) {
+  return(xtable.summary.splm(summary(x), caption = caption, label = label,
+                             align = align, digits = digits,
+                             display = display, auto = auto, ...))
+}
+
+xtable.summary.splm <- function(x, caption = NULL, label = NULL, align = NULL,
+                                digits = NULL, display = NULL, auto = FALSE,
+                                ...) {
+  x <- data.frame(x$CoefTable, check.names = FALSE)
+
+  class(x) <- c("xtable","data.frame")
+  caption(x) <- caption
+  label(x) <- label
+  if(auto && is.null(align))   align   <- xalign(x)
+  if(auto && is.null(digits))  digits  <- xdigits(x)
+  if(auto && is.null(display)) display <- xdisplay(x)
+  align(x) <- switch(1+is.null(align), align, c("r","r","r","r","r"))
+  digits(x) <- switch(1+is.null(digits), digits, c(0,4,4,2,4))
+  display(x) <- switch(1+is.null(display), display, c("s","f","f","f","f"))
+  return(x)
 }
 
+### package sphet
+### sphet objects
+xtable.sphet <- function(x, caption = NULL, label = NULL, align = NULL,
+                         digits = NULL, display = NULL, auto = FALSE, ...) {
+  return(xtable.summary.splm(summary(x), caption = caption, label = label,
+                             align = align, digits = digits,
+                             display = display, auto = auto, ...))
+}
+
+xtable.summary.sphet <- function(x, caption = NULL, label = NULL, align = NULL,
+                                 digits = NULL, display = NULL,
+                                 auto = FALSE, ...) {
+  return(xtable.summary.splm(x, caption = caption, label = label,
+                             align = align, digits = digits,
+                             display = display, auto = auto, ...))
+}
diff --git a/pkg/R/xtableFtable.R b/pkg/R/xtableFtable.R
new file mode 100644 (file)
index 0000000..3dc83d3
--- /dev/null
@@ -0,0 +1,210 @@
+### ftable objects, requested by Charles Roosen
+### Feature request #2248, 2/9/2012
+xtableFtable <- function(x, caption = NULL, label = NULL, align = NULL,
+                         digits = 0, display = NULL,
+                         quote = FALSE,
+                         method = c("non.compact", "row.compact",
+                                    "col.compact", "compact"),
+                         lsep = " $\\vert$ ", ...) {
+  method <- match.arg(method)
+  saveMethod <- method
+  xDim <- dim(x)
+  nRowVars <- length(attr(x, "row.vars"))
+  nColVars <- length(attr(x, "col.vars"))
+  if (nRowVars == 0){
+    if (method =="col.compact"){
+      method <- "non.compact"
+    } else if (method == "compact"){
+      method <- "row.compact"
+    }
+  }
+  if (nColVars == 0){
+    if (method =="row.compact"){
+      method <- "non.compact"
+    } else if (method == "compact"){
+      method <- "col.compact"
+    }
+  }
+  if (method == "non.compact"){
+    nCharCols <- nRowVars + 2
+    nCharRows <- nColVars + 1
+  }
+  if (method == "row.compact"){
+    nCharCols <- nRowVars + 2
+    nCharRows <- nColVars
+  }
+  if (method == "col.compact"){
+    nCharCols <- nRowVars + 1
+    nCharRows <- nColVars + 1
+  }
+  if (method == "compact"){
+    nCharCols <- nRowVars + 1
+    nCharRows <- nColVars
+  }
+
+  if(is.null(align)) {
+    align <- c(rep("l", nCharCols - 1), "l |", rep("r", xDim[2]))
+  }
+  if(is.null(display)) {
+    display <- c(rep("s", nCharCols), rep("d", xDim[2]))
+  }
+
+  attr(x, "ftableCaption") <- caption
+  attr(x, "ftableLabel") <- label
+  attr(x, "ftableAlign") <- align
+  attr(x, "ftableDigits") <- digits
+  attr(x, "quote") <- quote
+  attr(x, "ftableDisplay") <- display
+  attr(x, "method") <- method
+  attr(x, "lsep") <- lsep
+  attr(x, "nChars") <- c(nCharRows, nCharCols)
+  class(x) <- c("xtableFtable", "ftable")
+  return(x)
+}
+
+print.xtableFtable <- function(x,
+  type = getOption("xtable.type", "latex"),
+  file = getOption("xtable.file", ""),
+  append = getOption("xtable.append", FALSE),
+  floating = getOption("xtable.floating", TRUE),
+  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),
+  hline.after = getOption("xtable.hline.after", NULL),
+  NA.string = getOption("xtable.NA.string", ""),
+  only.contents = getOption("xtable.only.contents", FALSE),
+  add.to.row = getOption("xtable.add.to.row", NULL),
+  sanitize.text.function = getOption("xtable.sanitize.text.function", as.is),
+  sanitize.rownames.function = getOption("xtable.sanitize.rownames.function",
+                                         sanitize.text.function),
+  sanitize.colnames.function = getOption("xtable.sanitize.colnames.function",
+                                         sanitize.text.function),
+  math.style.negative = getOption("xtable.math.style.negative", FALSE),
+  math.style.exponents = getOption("xtable.math.style.exponents", FALSE),
+  html.table.attributes = getOption("xtable.html.table.attributes", "border=1"),
+  print.results = getOption("xtable.print.results", TRUE),
+  format.args = getOption("xtable.format.args", NULL),
+  rotate.rownames = getOption("xtable.rotate.rownames", FALSE),
+  rotate.colnames = getOption("xtable.rotate.colnames", FALSE),
+  booktabs = getOption("xtable.booktabs", FALSE),
+  scalebox = getOption("xtable.scalebox", NULL),
+  width = getOption("xtable.width", NULL),
+  comment = getOption("xtable.comment", TRUE),
+  timestamp = getOption("xtable.timestamp", date()),
+  ...) {
+  if (type == "latex"){
+    ## extract the information in the attributes
+    caption <- attr(x, "ftableCaption")
+    label <- attr(x, "ftableLabel")
+    align <- attr(x, "ftableAlign")
+    digits <- attr(x, "ftableDigits")
+    quote <- attr(x, "quote")
+    digits <- attr(x, "ftabelDigits")
+    method <- attr(x, "method")
+    lsep <- attr(x, "lsep")
+    nCharRows <- attr(x, "nChars")[1]
+    nCharCols <- attr(x, "nChars")[2]
+    nRowVars <- length(attr(x, "row.vars"))
+    nColVars <- length(attr(x, "col.vars"))
+
+    ## change class so format method will find format.ftable
+    ## even though format.ftable is not exported from 'stats'
+    class(x) <- "ftable"
+    fmtFtbl <- format(x, quote = quote, digits = digits,
+                      method = method, lsep = lsep)
+    attr(fmtFtbl, "caption") <- caption
+    attr(fmtFtbl, "label") <- label
+
+    ## sanitization is possible for row names and/or column names
+    ## row names
+    if (is.null(sanitize.rownames.function)) {
+      fmtFtbl[nCharRows, 1:nRowVars] <-
+        sanitize(fmtFtbl[nCharRows, 1:nRowVars], type = type)
+    } else {
+      fmtFtbl[nCharRows, 1:nRowVars] <-
+        sanitize.rownames.function(fmtFtbl[nCharRows, 1:nRowVars])
+    }
+    ## column names
+    if (is.null(sanitize.colnames.function)) {
+      fmtFtbl[1:nColVars, nCharCols - 1] <-
+        sanitize(fmtFtbl[1:nColVars, nCharCols - 1],
+                 type = type)
+    } else {
+      fmtFtbl[1:nColVars, nCharCols - 1] <-
+        sanitize.colnames.function(fmtFtbl[1:nColVars, nCharCols - 1])
+    }
+    ## rotations are possible
+    if (rotate.rownames){
+      fmtFtbl[1:dim(fmtFtbl)[1], 1:(nCharCols - 1)] <-
+        paste0("\\begin{sideways} ",
+               fmtFtbl[1:dim(fmtFtbl)[1], 1:(nCharCols - 1)],
+               "\\end{sideways}")
+    }
+    if (rotate.colnames){
+      if (rotate.rownames){
+        fmtFtbl[1:(nCharRows), (nCharCols):dim(fmtFtbl)[2]] <-
+          paste0("\\begin{sideways} ",
+                 fmtFtbl[1:(nCharRows), (nCharCols):dim(fmtFtbl)[2]],
+                 "\\end{sideways}")
+      } else {
+        fmtFtbl[1:(nCharRows), 1:dim(fmtFtbl)[2]] <-
+          paste0("\\begin{sideways} ",
+                 fmtFtbl[1:(nCharRows), 1:dim(fmtFtbl)[2]],
+                 "\\end{sideways}")
+      }
+    }
+
+
+    ## booktabs is incompatible with vertical lines in tables
+    if (booktabs) align <- gsub("|","", align, fixed = TRUE)
+    attr(fmtFtbl, "align") <- align
+    attr(fmtFtbl, "digits") <- digits
+    attr(fmtFtbl, "quote") <- quote
+    attr(fmtFtbl, "display") <- display
+
+    ## labels should be left aligned
+    for (i in 1:nCharRows){
+      fmtFtbl[i, nCharCols:dim(fmtFtbl)[2]] <-
+        paste0("\\multicolumn{1}{l}{ ",
+               fmtFtbl[i, nCharCols:dim(fmtFtbl)[2]], "}")
+    }
+
+
+    if(is.null(hline.after)) {
+      hline.after <- c(-1, nCharRows, dim(fmtFtbl)[1])
+    }
+    print.xtable(fmtFtbl, hline.after = hline.after,
+                 include.rownames = FALSE, include.colnames = FALSE,
+                 booktabs = booktabs,
+                 sanitize.text.function = as.is,
+                 file = file,
+                 append = append,
+                 floating = floating,
+                 floating.environment = floating.environment,
+                 table.placement = table.placement,
+                 caption.placement = caption.placement,
+                 caption.width = caption.width,
+                 latex.environments = latex.environments,
+                 tabular.environment = tabular.environment,
+                 size = size,
+                 NA.string = NA.string,
+                 only.contents = only.contents,
+                 add.to.row = add.to.row,,
+                 math.style.negative = math.style.negative,
+                 math.style.exponents = math.style.exponents,
+                 print.results = print.results,
+                 format.args = format.args,
+                 scalebox = scalebox,
+                 width = width,
+                 comment = comment,
+                 timestamp = timestamp,
+                 ...)
+  } else {
+    stop("print.xtableFtable not yet implemented for this type")
+  }
+}
+
diff --git a/pkg/R/xtableList.R b/pkg/R/xtableList.R
new file mode 100644 (file)
index 0000000..f4476a3
--- /dev/null
@@ -0,0 +1,275 @@
+### Function to create lists of tables\r
+xtableList <- function(x, caption = NULL, label = NULL, align = NULL,\r
+                       digits = NULL, display = NULL, ...) {\r
+  if (is.null(digits)){\r
+    digitsList <- vector("list", length(x))\r
+  } else {\r
+    if (!is.list(digits)){\r
+      digitsList <- vector("list", length(x))\r
+      for (i in 1:length(x)) digitsList[[i]] <- digits\r
+    }\r
+  }\r
+  if (is.null(display)){\r
+    displayList <- vector("list", length(x))\r
+  } else {\r
+    if (!is.list(display)){\r
+      displayList <- vector("list", length(x))\r
+      for (i in 1:length(x)) displayList[[i]] <- display\r
+    }\r
+  }\r
+  xList <- vector("list", length(x))\r
+  for (i in 1:length(x)){\r
+    xList[[i]] <- xtable(x[[i]], caption = caption, label = label,\r
+                         align = align, digits = digitsList[[i]],\r
+                         display = displayList[[i]], ...)\r
+    attr(xList[[i]], 'subheading') <- attr(x, 'subheadings')[[i]]\r
+  }\r
+  attr(xList, "message") <- attr(x, "message")\r
+  attr(xList, "caption") <- caption\r
+  attr(xList, "label") <- label\r
+  class(xList) <- c("xtableList")\r
+  return(xList)\r
+}\r
+\r
+print.xtableList <- function(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
+  caption.width = getOption("xtable.caption.width", NULL),\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 = NULL,\r
+  NA.string = getOption("xtable.NA.string", ""),\r
+  include.rownames = getOption("xtable.include.rownames", TRUE),\r
+  colnames.format = "single",\r
+  only.contents = getOption("xtable.only.contents", FALSE),\r
+  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
+  sanitize.subheadings.function =\r
+    getOption("xtable.sanitize.subheadings.function",\r
+              sanitize.text.function),\r
+  sanitize.message.function =\r
+    getOption("xtable.sanitize.message.function",\r
+              sanitize.text.function),\r
+  math.style.negative = getOption("xtable.math.style.negative", FALSE),\r
+  math.style.exponents = getOption("xtable.math.style.exponents", 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
+  rotate.rownames = getOption("xtable.rotate.rownames", FALSE),\r
+  rotate.colnames = getOption("xtable.rotate.colnames", FALSE),\r
+  booktabs = getOption("xtable.booktabs", FALSE),\r
+  scalebox = getOption("xtable.scalebox", NULL),\r
+  width = getOption("xtable.width", NULL),\r
+  comment = getOption("xtable.comment", TRUE),\r
+  timestamp = getOption("xtable.timestamp", date()),\r
+  ...)\r
+{\r
+  ## Get number of rows for each table in list of tables\r
+  nCols <- dim(x[[1]])[2]\r
+  rowNums <- sapply(x, dim)[1,]\r
+  combinedRowNums <- cumsum(rowNums)\r
+  combined <- do.call(rbind, x)\r
+  if (type == "latex"){\r
+    ## Special treatment if using booktabs\r
+    if (booktabs){\r
+      tRule <- "\\toprule"\r
+      mRule <- "\\midrule"\r
+      bRule <- "\\bottomrule"\r
+    } else {\r
+      tRule <- "\\hline"\r
+      mRule <- "\\hline"\r
+      bRule <- "\\hline"\r
+    }\r
+    ## Sanitize subheadings if required\r
+    if (!is.null(sanitize.subheadings.function)) {\r
+      for (i in 1:length(x)){\r
+        attr(x[[i]], 'subheading') <-\r
+          sanitize.subheadings.function(attr(x[[i]], 'subheading'))\r
+      }\r
+    }\r
+    ## Sanitize message if required\r
+    if (!is.null(sanitize.message.function)) {\r
+      xMessage <- attr(x, 'message')\r
+      xMessage <- sapply(xMessage, sanitize.message.function)\r
+      attr(x, 'message') <- xMessage\r
+    }\r
+    if (colnames.format == "single"){\r
+\r
+      add.to.row <- list(pos = NULL, command = NULL)\r
+      add.to.row$pos <- as.list(c(0, combinedRowNums[-length(x)],\r
+                                  dim(combined)[1]))\r
+      command <- sapply(x, attr, "subheading")\r
+\r
+      for (i in 1:length(x)){\r
+        if( !is.null(command[[i]]) ){\r
+          add.to.row$command[i] <-\r
+            paste0(mRule,"\n\\multicolumn{", nCols, "}{l}{",\r
+                   command[[i]],\r
+                   "}\\\\\n")\r
+        } else {\r
+          add.to.row$command[i] <- paste0(mRule, "\n")\r
+        }\r
+      }\r
+      ## Changed at request of Russ Lenth\r
+      ## add.to.row$command[1:length(x)] <-\r
+      ##   paste0(mRule,"\n\\multicolumn{", nCols, "}{l}{", command, "}\\\\\n")\r
+      \r
+      if ( (booktabs) & length(attr(x, "message") > 0) ){\r
+        attr(x, "message")[1] <-\r
+          paste0("\\rule{0em}{2.5ex}", attr(x, "message")[1])\r
+      }\r
+      add.to.row$command[length(x) + 1] <-\r
+        paste0("\n\\multicolumn{", nCols, "}{l}{",\r
+               attr(x, "message"), "}\\\\\n",\r
+               collapse = "")\r
+      add.to.row$command[length(x) + 1] <-\r
+        paste0(bRule, add.to.row$command[length(x) + 1])\r
+\r
+      class(combined) <- c("xtableList", "data.frame")\r
+      hline.after <- c(-1)\r
+      include.colnames <- TRUE\r
+    }\r
+\r
+    ## Create headings for columns if multiple headings are needed\r
+    if (colnames.format == "multiple"){\r
+      if (is.null(sanitize.colnames.function)) {\r
+        colHead <- names(x[[1]])\r
+      } else {\r
+        colHead <- sanitize.colnames.function(names(x[[1]]))\r
+      }\r
+      if (rotate.colnames) {\r
+        colHead <- paste("\\begin{sideways}", colHead, "\\end{sideways}")\r
+      }\r
+      colHead <- paste0(colHead, collapse = " & ")\r
+      if (include.rownames) {\r
+        colHead <- paste0(" & ", colHead)\r
+      }\r
+      colHead <- paste0(tRule, "\n", colHead, " \\\\", mRule, "\n")\r
+      add.to.row <- list(pos = NULL, command = NULL)\r
+      add.to.row$pos <- as.list(c(0, c(combinedRowNums[1:length(x)])))\r
+      command <- sapply(x, attr, "subheading")\r
+\r
+\r
+      add.to.row$command[1] <-\r
+        if( !is.null(command[[1]]) ){\r
+          add.to.row$command[1] <-\r
+            paste0("\n\\multicolumn{", nCols, "}{l}{",\r
+                   command[[1]],\r
+                   "}\\\\ \n", colHead, "\n")\r
+        } else {\r
+          add.to.row$command[1] <- colHead\r
+        }\r
+\r
+      for (i in 2:length(x)) {\r
+        add.to.row$command[i] <-\r
+          if( !is.null(command[[i]]) ) {\r
+            paste0(bRule,\r
+                   "\\\\ \n\\multicolumn{", nCols, "}{l}{",\r
+                   command[[i]], "}",\r
+                   "\\\\ \n",\r
+                   colHead)\r
+          } else {\r
+            add.to.row$command[i] <- paste0("\n", colHead)\r
+          }\r
+      }\r
+      \r
+      ## Changed at request of Russ Lenth\r
+      ## add.to.row$command[1] <-\r
+      ##   paste0("\n\\multicolumn{", nCols, "}{l}{", command[1],\r
+      ##          "}", " \\\\ \n",\r
+      ##          colHead)\r
+      ## add.to.row$command[2:length(x)] <-\r
+      ##   paste0(bRule,\r
+      ##          "\\\\ \n\\multicolumn{", nCols, "}{l}{",\r
+      ##          command[2:length(x)], "}",\r
+      ##          "\\\\ \n",\r
+      ##          colHead)\r
+      if ( (booktabs) & length(attr(x, "message") > 0) ){\r
+        attr(x, "message")[1] <-\r
+          paste0("\\rule{0em}{2.5ex}", attr(x, "message")[1])\r
+      }\r
+      add.to.row$command[length(x) + 1] <-\r
+        paste0("\n\\multicolumn{", nCols, "}{l}{",\r
+               attr(x, "message"), "}\\\\\n",\r
+               collapse = "")\r
+      add.to.row$command[length(x) + 1] <-\r
+        paste0(bRule, add.to.row$command[length(x) + 1])\r
+\r
+      class(combined) <- c("xtableList", "data.frame")\r
+      hline.after <- NULL\r
+\r
+      include.colnames <- FALSE\r
+    }\r
+\r
+    print.xtable(combined,\r
+                 type = type,\r
+                 floating = floating,\r
+                 floating.environment = floating.environment,\r
+                 table.placement = table.placement,\r
+                 caption.placement = caption.placement,\r
+                 caption.width = caption.width,\r
+                 latex.environments = latex.environments,\r
+                 tabular.environment = tabular.environment,\r
+                 size = size,\r
+                 hline.after = hline.after,\r
+                 NA.string = NA.string,\r
+                 include.rownames = include.rownames,\r
+                 include.colnames = include.colnames,\r
+                 only.contents = only.contents,\r
+                 add.to.row = add.to.row,\r
+                 sanitize.text.function = sanitize.text.function,\r
+                 sanitize.rownames.function = sanitize.rownames.function,\r
+                 sanitize.colnames.function = sanitize.colnames.function,\r
+                 math.style.negative = math.style.negative,\r
+                 math.style.exponents = math.style.exponents,\r
+                 html.table.attributes = html.table.attributes,\r
+                 print.results = print.results,\r
+                 format.args = format.args,\r
+                 rotate.rownames = rotate.rownames,\r
+                 rotate.colnames = rotate.colnames,\r
+                 booktabs = booktabs,\r
+                 scalebox = scalebox,\r
+                 width = width,\r
+                 comment = comment,\r
+                 timestamp = timestamp,\r
+                 ...)\r
+  } else {\r
+    stop("print.xtableList not yet implemented for this type")\r
+  }\r
+}\r
+\r
+\r
+### Uses xtableList\r
+xtableLSMeans <- function(x, caption = NULL, label = NULL,\r
+                          align = NULL, digits = NULL,\r
+                          display = NULL, auto = FALSE,\r
+                          ...){\r
+  if (attr(x, "estName") == "lsmean"){\r
+    xList <- split(x, f = x[, 2])\r
+    for (i in 1:length(xList)){\r
+      xList[[i]] <- as.data.frame(xList[[i]][, -2])\r
+    }\r
+    attr(xList, "subheadings") <-\r
+      paste0(dimnames(x)[[2]][2], " = ", levels(x[[2]]))\r
+    attr(xList, "message") <- c("", attr(x, "mesg"))\r
+    xList <- xtableList(xList, caption = caption, label = label,\r
+                        align = align, digits = digits,\r
+                        display = display, auto = auto, ...)\r
+  } else {\r
+    xList <- x\r
+    xList <- xtable.data.frame(xList, caption = caption, label = label,\r
+                               align = align, digits = digits,\r
+                               display = display, auto = auto, ...)\r
+  }\r
+  return(xList)\r
+}\r
diff --git a/pkg/R/xtableMatharray.R b/pkg/R/xtableMatharray.R
new file mode 100644 (file)
index 0000000..c782f59
--- /dev/null
@@ -0,0 +1,36 @@
+### xtableMatharray object\r
+### To deal with numeric arrays such as a variance-covariance matrix\r
+### From a request by James Curran, 16 October 2015\r
+xtableMatharray <- function(x, caption = NULL, label = NULL,\r
+                            align = NULL, digits = NULL,\r
+                            display = NULL, auto = FALSE,\r
+                            ...) {\r
+  class(x) <- c("xtableMatharray","matrix")\r
+  xtbl <- xtable.matrix(x,\r
+                        caption = caption, label = label, align = align,\r
+                        digits = digits, display = display, auto = auto,\r
+                        ...)\r
+  class(xtbl) <- c("xtableMatharray","xtable","data.frame")\r
+  return(xtbl)\r
+}\r
+\r
+print.xtableMatharray <- function(x,\r
+           print.results = TRUE,\r
+           format.args = getOption("xtable.format.args", NULL),\r
+           scalebox = getOption("xtable.scalebox", NULL),\r
+           comment = FALSE,\r
+           timestamp = NULL,\r
+           ...)\r
+{\r
+  class(x) <- c("xtableMatharray","data.frame")\r
+  print.xtable(x, floating = FALSE,\r
+               tabular.environment = 'array',\r
+               include.rownames = FALSE, include.colnames = FALSE,\r
+               hline.after = NULL,\r
+               print.results = print.results,\r
+               format.args = format.args,\r
+               scalebox = scalebox,\r
+               comment = comment,\r
+               timestamp = timestamp,\r
+               ...)\r
+}\r
index 412059915353f2687c6e415d8950cdb677395229..ce44b4dfe323b3a0a8e57099384c265df2d6c207 100644 (file)
@@ -45,7 +45,7 @@
   ...)}\r
 \arguments{\r
   \item{x}{An object of class \code{"xtable"}.}\r
-  \item{type}{Type of table to produce.  Possible values for \code{type}\r
+  \item{type}{Type of table to produce. Possible values for \code{type}\r
     are \code{"latex"} or \code{"html"}.\r
     Default value is \code{"latex"}.}\r
   \item{file}{Name of file where the resulting code should be saved.  If\r
     $-$ for the negative sign (as was the behavior prior to version 1.5-3).\r
     Default value is \code{FALSE}.}\r
   \item{math.style.exponents}{In a LaTeX table, if \code{TRUE} or\r
-    \code{"$$"}, then use \code{$5 \times 10^{5}$} for 5e5. If\r
-    \code{"ensuremath"}, then use \code{\ensuremath{5 \times 10^{5}}}\r
+    \code{"$$"}, then use \verb{$5 \times 10^{5}$} for 5e5. If\r
+    \code{"ensuremath"}, then use \verb{\\ensuremath{5 \times 10^{5}}}\r
     for 5e5. If \code{"UTF-8"} or \code{"UTF-8"}, then use UTF-8 to\r
     approximate the LaTeX typsetting for 5e5.\r
     Default value is \code{FALSE}.}\r
   \item{comment}{If \code{TRUE}, the version and timestamp comment is\r
     included.  Default value is \code{TRUE}. }\r
   \item{timestamp}{Timestamp to include in LaTeX comment.  Set this\r
-    to \code{NULL} to exclude the timestamp. Default value is \code{date()}. }\r
+    to \code{NULL} to exclude the timestamp. Default value is\r
+    \code{date()}. }\r
   \item{...}{Additional arguments.  (Currently ignored.) }\r
 }\r
 \details{\r
   \code{sanitize.text.function=function(x){x}}.\r
 \r
   From version 1.6-1 the default values for the arguments other than\r
-  \code{x} are obtainined using \code{getOption()}.  Hence the user can\r
+  \code{x} are obtained using \code{getOption()}.  Hence the user can\r
   set the values once with \code{options()} rather than setting them in\r
   every call to \code{print.xtable()}.\r
 \r
diff --git a/pkg/man/print.xtableMatharray.Rd b/pkg/man/print.xtableMatharray.Rd
new file mode 100644 (file)
index 0000000..b521e26
--- /dev/null
@@ -0,0 +1,96 @@
+\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 = TRUE,\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{TRUE}.}\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
+ This command prints an array of numbers which may be included in a\r
+ mathematical expression in a LaTeX document created using \pkg{Sweave}\r
+ or \pkg{knitr}. Internally it calls \code{print.data.frame} but with\r
+ special values for the arguments, namely that the tabular environment\r
+ is \code{array}, row names and column names are not included, and there\r
+ are no horizontal lines. Note that the default values for the arguments\r
+ \code{comment} and \code{timestamp} are different to the default values\r
+ for \code{print.xtable}, the justification being that comments would\r
+ make the resulting LaTeX harder to read.\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
+### Simple test of print.xtableMatharray\r
+print.xtableMatharray(xtable(V, display = rep("E", 4)))\r
+\r
+class(V) <- c("xtableMatharray")\r
+class(V)\r
+\r
+### Test without any additional arguments\r
+mth <- xtableMatharray(V)\r
+str(mth)\r
+print(mth)\r
+\r
+### Test with arguments to xtable\r
+mth <- xtableMatharray(V, display = rep("E", 4))\r
+str(mth)\r
+print(mth)\r
+\r
+mth <- xtableMatharray(V, digits = 6)\r
+str(mth)\r
+print(mth)\r
+\r
+### Test with additional print.xtableMatharray arguments\r
+mth <- xtableMatharray(V, digits = 6)\r
+str(mth)\r
+print(mth, format.args = list(decimal.mark = ","))\r
+print(mth, scalebox = 0.5)\r
+print(mth, comment = TRUE)\r
+print(mth, timestamp = "2000-01-01")\r
+print(mth, comment = TRUE, timestamp = "2000-01-01")\r
+}\r
+\r
+\keyword{print}\r
diff --git a/pkg/man/sanitize.Rd b/pkg/man/sanitize.Rd
new file mode 100644 (file)
index 0000000..f228a6d
--- /dev/null
@@ -0,0 +1,105 @@
+\name{sanitize}\r
+\alias{sanitize}\r
+\alias{sanitize.numbers}\r
+\alias{sanitize.final}\r
+\alias{as.is}\r
+\alias{as.math}\r
+\r
+\title{\r
+  Sanitization Functions\r
+}\r
+\description{\r
+  Functions for sanitizing elements of a table produced by\r
+  \pkg{xtable}. Used for dealing with characters which have special\r
+  meaning in the output format.\r
+}\r
+\usage{\r
+sanitize(str, type = "latex")\r
+sanitize.numbers(str, type, math.style.negative = FALSE,\r
+                 math.style.exponents = FALSE)\r
+sanitize.final(str, type)\r
+as.is(str)\r
+as.math(str, ...)\r
+}\r
+\r
+\arguments{\r
+  \item{str}{A character object to be sanitized.}\r
+  \item{type}{Type of table to produce. Possible values for \code{type}\r
+    are \code{"latex"} or \code{"html"}.\r
+    Default value is \code{"latex"}.}\r
+  \item{math.style.negative}{In a LaTeX table, if \code{TRUE}, then use\r
+    $-$ for the negative sign (as was the behavior prior to version 1.5-3).\r
+    Default value is \code{FALSE}.}\r
+  \item{math.style.exponents}{In a LaTeX table, if \code{TRUE} or\r
+    \code{"$$"}, then use \verb{$5 \times 10^{5}$} for 5e5. If\r
+    \code{"ensuremath"}, then use \verb{\ensuremath{5 \times 10^{5}}}\r
+    for 5e5. If \code{"UTF-8"} or \code{"UTF-8"}, then use UTF-8 to\r
+    approximate the LaTeX typsetting for 5e5.\r
+    Default value is \code{FALSE}.}\r
+  \item{\dots}{Additional arguments. Character strings or character\r
+    vectors.}\r
+}\r
+\details{\r
+\r
+  If \code{type} is \code{"latex"}, \code{sanitize()} will replace\r
+  special characters such as \verb{&} and the like by strings which will\r
+  reproduce the actual character, e.g. \verb{&} is replaced by\r
+  \verb{\\&}.\r
+\r
+  If \code{type} is \code{"html"}, \code{sanitize()} will replace\r
+  special characters such as \verb{<} and the like by strings which will\r
+  reproduce the actual character, e.g. \verb{<} is replaced by\r
+  \verb{&lt;}.\r
+\r
+  When \code{math.style.negative} is \code{TRUE}, and \code{type} is\r
+  \code{"latex"}, $-$ is used for the negative sign rather than a\r
+  simple hyphen (-). No effect when \code{type} is \code{"html"}.\r
+\r
+  When \code{type} is \code{"latex"}, and \code{math.style.exponents}\r
+  is \code{TRUE} or \verb{"$$"}, then use \verb{$5 \times 10^{5}$} for\r
+  5e5. If \code{"ensuremath"}, then use \verb{\ensuremath{5 \times\r
+  10^{5}}} for 5e5. If \code{"UTF-8"} or \code{"UTF-8"}, then use UTF-8\r
+  to approximate the LaTeX typsetting for 5e5.\r
+\r
+  When \code{type} is \code{"latex"} \code{sanitize.final} has no\r
+  effect. When \code{type} is \code{"html"}, multiple spaces are\r
+  replaced by a single space and occurrences of \code{' align="left"'}\r
+  are eliminated.\r
+\r
+  \code{as.is} and \code{as.math} are trivial helper functions to\r
+  disable sanitizing and to insert a some mathematics in a string\r
+  respectively.\r
+}\r
+\value{\r
+  Returns the sanitized character object.\r
+}\r
+\r
+\author{\r
+  Code was extracted from \code{print.xtable()}, in version 1.8.0 of\r
+  \pkg{xtable}. Various authors contributed the original code: Jonathan\r
+  Swinton <jonathan@swintons.net>, Uwe Ligges\r
+  <ligges@statistik.uni-dortmund.de>, and probably David B. Dahl\r
+  <dahl@stat.byu.edu>.\r
+  \code{as.is} and \code{as.math} suggested and provided by Stefan\r
+  Edwards <sme@iysik.com>.\r
+}\r
+\r
+\examples{\r
+insane <- c("&",">", ">","_","\%","$","\\\\","#","^","~","{","}")\r
+names(insane) <- c("Ampersand","Greater than","Less than",\r
+                   "Underscore","Percent","Dollar",\r
+                   "Backslash","Hash","Caret","Tilde",\r
+                   "Left brace","Right brace")\r
+sanitize(insane, type = "latex")\r
+insane <- c("&",">","<")\r
+names(insane) <- c("Ampersand","Greater than","Less than")\r
+sanitize(insane, type = "html")\r
+x <- rnorm(10)\r
+sanitize.numbers(x, "latex", TRUE)\r
+sanitize.numbers(x*10^(10), "latex", TRUE, TRUE)\r
+sanitize.numbers(x, "html", TRUE, TRUE)\r
+as.is(insane)\r
+as.math("x10^10", ": mathematical expression")\r
+}\r
+\r
+\keyword{print }\r
index c117fcf6c68d8b78776d9a7315deffcfd9b2f053..88e9d2f9036b4d6a28cddd9b0f334402bf094302 100644 (file)
@@ -25,6 +25,9 @@
   These functions are private functions used by \code{print.xtable}.  They are
   not intended to be used elsewhere.
 }
-\author{David Dahl \email{dahl@stat.byu.edu} with contributions and suggestions from many others (see source code).}
+\author{
+  David Dahl \email{dahl@stat.byu.edu} with contributions and
+  suggestions from many others (see source code).
+}
 \seealso{\code{\link{print.xtable}}}
 \keyword{print}
diff --git a/pkg/man/xtable-internal.Rd b/pkg/man/xtable-internal.Rd
new file mode 100644 (file)
index 0000000..63fbc73
--- /dev/null
@@ -0,0 +1,13 @@
+\name{xtable-internal}\r
+\alias{xtableLSMeans}\r
+\r
+\r
+\title{Internal xtable Functions}\r
+\description{\r
+  Internal functions for the package xtable\r
+}\r
+\details{\r
+  Functions which are either not intended to be called by the user or\r
+  are waiting to be documented.\r
+}\r
+\keyword{ internal }\r
index cb33e88af9aaff4aece5853cd848e0db536d6a02..29efa7c0f9d22bc1046b5647b3677784930b8758 100644 (file)
@@ -7,6 +7,7 @@
 \alias{xtable.glm}
 \alias{xtable.lm}
 \alias{xtable.matrix}
+\alias{xtable.xtableMatharray}
 \alias{xtable.prcomp}
 \alias{xtable.coxph}
 \alias{xtable.summary.aov}
 \alias{xtable.ts}
 \alias{xtable.table}
 \alias{xtable.zoo}
+\alias{xtable.sarlm}
+\alias{xtable.summary.sarlm}
+\alias{xtable.gmsar}
+\alias{xtable.summary.gmsar}
+\alias{xtable.stsls}
+\alias{xtable.summary.stsls}
+\alias{xtable.sarlm.pred}
+\alias{xtable.lagImpact}
+\alias{xtable.splm}
+\alias{xtable.summary.splm}
+\alias{xtable.sphet}
+\alias{xtable.summary.sphet}
+\alias{xtable.spautolm}
+\alias{xtable.summary.spautolm}
+
+
 \title{Create Export Tables}
 \description{
-  Convert an R object to an \code{xtable} object, which can
+  Convert an \R object to an \code{xtable} object, which can
   then be printed as a LaTeX or HTML table.
 }
 \usage{
@@ -27,7 +44,7 @@ xtable(x, caption = NULL, label = NULL, align = NULL, digits = NULL,
        display = NULL, auto = FALSE, ...)
 }
 \arguments{
-  \item{x}{An R object of class found among \code{methods(xtable)}.  See
+  \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 or 2 containing the
     table's caption or title.  If length is 2, the second item is the
@@ -110,9 +127,11 @@ xtable(x, caption = NULL, label = NULL, align = NULL, digits = NULL,
   have attributes \code{caption} and \code{label}, but must have
   attributes \code{align}, \code{digits}, and \code{display}.
 }
-\value{An object of class \code{"xtable"} which inherits the
-  \code{data.frame} class and contains several additional attributes
-  specifying the table formatting options.
+\value{
+  For most \code{xtable} methods, an object of class \code{"xtable"}
+  which inherits the \code{data.frame} class and contains several
+  additional attributes specifying the table formatting options.
+
 }
 \author{David Dahl \email{dahl@stat.byu.edu} with contributions and
   suggestions from many others (see source code).
@@ -120,10 +139,9 @@ xtable(x, caption = NULL, label = NULL, align = NULL, digits = NULL,
 \seealso{
   \code{\link{print.xtable}}, \code{\link{caption}},
   \code{\link{label}}, \code{\link{align}}, \code{\link{digits}},
-  \code{\link{display}}
-
-  \code{\link{autoformat}}, \code{\link{xalign}}, \code{\link{xdigits}},
-  \code{\link{xdisplay}}
+  \code{\link{display}}, \code{\link{autoformat}}, \code{\link{xalign}},
+  \code{\link{xdigits}}, \code{\link{xdisplay}},
+  \code{\link{xtableMatharray}}, \code{\link{xtableList}}
 }
 \examples{
 
diff --git a/pkg/man/xtableFtable.Rd b/pkg/man/xtableFtable.Rd
new file mode 100644 (file)
index 0000000..2e743b1
--- /dev/null
@@ -0,0 +1,347 @@
+\name{xtableFtable}
+\alias{xtableFtable}
+\alias{print.xtableFtable}
+
+\title{
+  Create and Export Flat Tables
+}
+\description{
+  \code{xtableFtable} creates an object which contains information about
+  a flat table which can be used by \code{print.xtableFtable} to produce
+  a character string which when included in a document produces a nicely
+  formatted flat table.
+}
+\usage{
+xtableFtable(x, caption = NULL, label = NULL,
+             align = NULL, digits = 0, display = NULL,
+             quote = FALSE,
+             method = c("non.compact", "row.compact",
+                         "col.compact", "compact"),
+             lsep = " $\\\\vert$ ", ...)
+
+\method{print}{xtableFtable}(x,
+  type = getOption("xtable.type", "latex"),
+  file = getOption("xtable.file", ""),
+  append = getOption("xtable.append", FALSE),
+  floating = getOption("xtable.floating", TRUE),
+  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),
+  hline.after = getOption("xtable.hline.after", NULL),
+  NA.string = getOption("xtable.NA.string", ""),
+  only.contents = getOption("xtable.only.contents", FALSE),
+  add.to.row = getOption("xtable.add.to.row", NULL),
+  sanitize.text.function = getOption("xtable.sanitize.text.function", as.is),
+  sanitize.rownames.function = getOption("xtable.sanitize.rownames.function",
+                                         sanitize.text.function),
+  sanitize.colnames.function = getOption("xtable.sanitize.colnames.function",
+                                         sanitize.text.function),
+  math.style.negative = getOption("xtable.math.style.negative", FALSE),
+  math.style.exponents = getOption("xtable.math.style.exponents", FALSE),
+  html.table.attributes = getOption("xtable.html.table.attributes",
+                                    "border=1"),
+  print.results = getOption("xtable.print.results", TRUE),
+  format.args = getOption("xtable.format.args", NULL),
+  rotate.rownames = getOption("xtable.rotate.rownames", FALSE),
+  rotate.colnames = getOption("xtable.rotate.colnames", FALSE),
+  booktabs = getOption("xtable.booktabs", FALSE),
+  scalebox = getOption("xtable.scalebox", NULL),
+  width = getOption("xtable.width", NULL),
+  comment = getOption("xtable.comment", TRUE),
+  timestamp = getOption("xtable.timestamp", date()),
+  ...)
+}
+
+\arguments{
+  \item{x}{For \code{xtableFtable}, an object of class
+  \code{"ftable"}. For \code{print.xtableFtable}, an object of class
+  \code{c("xtableFtable", "ftable")}.}
+  \item{caption}{Character vector of length 1 or 2 containing the
+    table's caption or title.  If length is 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}. }
+  \item{align}{Character vector of length equal to the number of columns
+    of the resulting table, indicating the alignment of the corresponding
+    columns.  Also, \code{"|"} may be used to produce vertical lines
+    between columns in LaTeX tables, but these are effectively ignored
+    when considering the required length of the supplied vector.  If a
+    character vector of length one is supplied, it is split as
+    \code{strsplit(align, "")[[1]]} before processing. For a flat table,
+    the number of columns is the number of columns of data, plus the
+    number of row variables in the table, plus one for the row names,
+    even though row names are not printed.
+    Use \code{"l"}, \code{"r"}, and \code{"c"} to
+    denote left, right, and center alignment, respectively.  Use
+    \code{"p{3cm}"} etc. for a LaTeX column of the specified width. For
+    HTML output the \code{"p"} alignment is interpreted as \code{"l"},
+    ignoring the width request.
+    If \code{NULL} all row variable labels will be left aligned,
+    separated from the data columns by a vertical line, and all data
+    columns will be right aligned. The actual length of \code{align}
+    depends on the value of \code{method}.}
+  \item{digits}{
+    Numeric vector of length equal to one (in which case it will be
+    replicated as necessary) or to the number of columns in the
+    resulting table. Since data in the table consists of
+    counts, the default is 0. If the value of \code{digits} is negative, the
+    corresponding columns are displayed in scientific format
+    with \code{abs(digits)} digits.}
+  \item{display}{
+    Character vector of length equal to the number of columns of the
+    resulting table, indicating the format for the corresponding columns.
+    These values are passed to the \code{formatC}
+    function.  Use \code{"d"} (for integers), \code{"f"}, \code{"e"},
+    \code{"E"}, \code{"g"}, \code{"G"}, \code{"fg"} (for reals), or
+    \code{"s"} (for strings).  \code{"f"} gives numbers in the usual
+    \code{xxx.xxx} format; \code{"e"} and \code{"E"} give
+    \code{n.ddde+nn} or \code{n.dddE+nn} (scientific format); \code{"g"}
+    and \code{"G"} put \code{x[i]} into scientific format only if it
+    saves space to do so.  \code{"fg"} uses fixed format as \code{"f"},
+    but \code{digits} as number of \emph{significant} digits.  Note that
+    this can lead to quite long result strings.
+    If \code{NULL} all row variable names and labels will have format
+    \code{"s"}, and all data columns will have format \code{"d"}. The
+    actual length of \code{display} depends on the value of
+    \code{method}.}
+  \item{quote}{a character string giving the set of quoting characters
+    for \code{format.ftable} used in \code{print.xtableFtable}; to
+    disable quoting altogether, use \code{quote=""}.}
+
+  \item{method}{string specifying how the \code{"xtableFtable"} object is
+    printed in the \code{print} method.  Can be abbreviated.  Available
+    methods are (see the examples in \code{\link{print.ftable}}):
+    \describe{
+      \item{"non.compact"}{the default representation of an
+        \code{"ftable"} object.}
+      \item{"row.compact"}{a row-compact version without empty cells
+        below the column labels.}
+      \item{"col.compact"}{a column-compact version without empty cells
+        to the right of the row labels.}
+      \item{"compact"}{a row- and column-compact version.  This may imply
+        a row and a column label sharing the same cell.  They are then
+        separated by the string \code{lsep}.}
+    }
+  }
+  \item{lsep}{only for \code{method = "compact"}, the separation string
+    for row and column labels.}
+  \item{type}{Type of table to produce. Possible values for \code{type}
+    are \code{"latex"} or \code{"html"}.
+    Default value is \code{"latex"} and is the only type implemented so far.}
+  \item{file}{Name of file where the resulting code should be saved.  If
+    \code{file=""}, output is displayed on screen.  Note that the
+    function also (invisibly) returns a character vector of the results
+    (which can be helpful for post-processing).
+    Default value is \code{""}.}
+  \item{append}{If \code{TRUE} and \code{file!=""}, code will be
+    appended to \code{file} instead of overwriting \code{file}.
+    Default value is \code{FALSE}.}
+  \item{floating}{If \code{TRUE} and \code{type="latex"}, the resulting
+    table will be a floating table (using, for example,
+    \code{\\begin\{table\}} and \code{\\end\{table\}}).  See
+    \code{floating.environment} below.
+    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 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
+    \code{table.placement} where \code{table.placement} must be
+    \code{NULL} or contain only elements of
+    \{"h","t","b","p","!","H"\}.
+    Default value is \code{"ht"}.}
+  \item{caption.placement}{The caption will be placed at the bottom
+    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 specified LaTeX environments (provided as
+    a character vector) will enclose the tabular environment.
+    Default value is \code{"center"}. }
+  \item{tabular.environment}{When \code{type="latex"}, the tabular
+    environment that will be used.
+    When working with tables that extend more than one page, using
+    \code{tabular.environment="longtable"} with the corresponding
+    LaTeX package (see Fairbairns, 2005) allows one to typeset them
+    uniformly. Note that \code{floating} should be set to
+    \code{FALSE} when using the \code{longtable} environment.
+    Default value is \code{"tabular"}.}
+  \item{size}{A character vector that is inserted just before the
+    tabular environment starts. This can be used to set the font size
+    and a variety of other table settings. Initial backslashes are
+    automatically prefixed, if not supplied by user.
+    Default value is \code{NULL}. }
+  \item{hline.after}{When \code{type="latex"}, a vector of numbers
+    between -1 and \code{nrow(x)}, inclusive, indicating the rows after
+    which a horizontal line should appear.  Repeated values are
+    allowed. If \code{NULL} the default is to draw a line before before
+    starting the table, after the column variable names and labels, and
+    at the end of the table.}
+  \item{NA.string}{String to be used for missing values in table
+    entries.
+    Default value is \code{""}.}
+ \item{only.contents}{If \code{TRUE} only the rows of the
+    table are printed.
+    Default value is \code{FALSE}. }
+  \item{add.to.row}{A list of two components. The first component (which
+    should be called 'pos') is a list that contains the position of rows on
+    which extra commands should be added at the end. The second
+    component (which should be called 'command') is a character vector
+    of the same length as the first component, which contains the command
+    that should be added at the end of the specified rows.
+    Default value is \code{NULL}, i.e. do not add commands.}
+  \item{sanitize.text.function}{Since the table entries are counts no
+    sanitization is necessary. The default is \code{as.is}, which is the
+    function which makes no changes. This also applies to the labels for
+    the row and column variables since these are also part of the table
+    which is printed using a call to \code{print.xtable}.}
+  \item{sanitize.rownames.function}{Like the
+    \code{sanitize.text.function}, but applicable to row names.
+    The default uses the \code{sanitize.text.function}. }
+  \item{sanitize.colnames.function}{Like the
+    \code{sanitize.text.function}, but applicable to column names.
+    The default uses the \code{sanitize.text.function}. }
+  \item{math.style.negative}{In a LaTeX table, if \code{TRUE}, then use
+    $-$ for the negative sign (as was the behavior prior to version 1.5-3).
+    Default value is \code{FALSE}.}
+  \item{math.style.exponents}{In a LaTeX table, if \code{TRUE} or
+    \code{"$$"}, then use \verb{$5 \times 10^{5}$} for 5e5. If
+    \code{"ensuremath"}, then use \verb{\\ensuremath{5 \times 10^{5}}}
+    for 5e5. If \code{"UTF-8"} or \code{"UTF-8"}, then use UTF-8 to
+    approximate the LaTeX typsetting for 5e5.
+    Default value is \code{FALSE}.}
+  \item{html.table.attributes}{In an HTML table, attributes associated
+    with the \code{<TABLE>} 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.
+  Default value is \code{TRUE}.}
+  \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 =
+      ","))}. The arguments \code{digits} and \code{format} should not be
+    included in this list.
+    Default value is \code{NULL}.}
+  \item{rotate.rownames}{If \code{TRUE}, the row names and labels, and
+    column variable names are displayed vertically in LaTeX.
+    Default value is \code{FALSE}.}
+  \item{rotate.colnames}{If \code{TRUE}, the column names and labels,
+    and row variable names are displayed vertically in LaTeX.
+    Default value is \code{FALSE}.}
+  \item{booktabs}{If \code{TRUE}, the \code{toprule}, \code{midrule} and
+    \code{bottomrule} commands from the LaTeX "booktabs" package are used
+    rather than \code{hline} for the horizontal line tags. }
+  \item{scalebox}{If not \code{NULL}, a \code{scalebox} clause will be
+    added around the tabular environment with the specified value used
+    as the scaling factor.
+    Default value is \code{NULL}.}
+  \item{width}{If not \code{NULL}, the specified value is included in
+    parentheses between the tabular environment \code{begin} tag and the
+    alignment specification.  This allows specification of the table
+    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.
+    Default value is \code{NULL}.}
+  \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. Default value is
+    \code{date()}. }
+  \item{...}{Additional arguments.  (Currently ignored.) }
+}
+\details{
+  \code{xtableFtable} carries out some calculations to determine the
+    number of rows and columns of names and labels which will be in the
+    table when formatted as a flat table, which depends on the value of
+    \code{method}. It uses the results of those calculations to set
+    sensible values for \code{align} and \code{display} if these have
+    not been supplied. It attaches attributes to the resulting object
+    which specify details of the function call which are needed when
+    printing the resulting object which is of class
+    \code{c("xtableFtable", "ftable")}.
+
+    \code{print.xtableFtable} uses the attributes attached to an object
+    of class \code{c("xtableFtable", "ftable")} to create a suitable
+    character matrix object for subsequent printing. Formatting is
+    carried out by changing the class of the \code{c("xtableFtable",
+    "ftable")} to \code{"ftable"} then using the generic \code{format}
+    to invoke \code{format.ftable}, from the \pkg{stats} package. The
+    matrix object produced is then printed via a call to
+    \code{print.xtable}.
+
+    Note that at present there is no code for \code{type = "html"}.
+}
+\value{
+  For \code{xtableFtable} an object of class \code{c("xtableFtable",
+    "ftable")}, with attributes
+  \item{ftableCaption}{the value of the \code{caption} argument}
+  \item{ftableLabel}{the value of the \code{label} argument}
+  \item{ftableAlign}{the value of the \code{label} argument}
+  \item{ftableDigits}{the value of the \code{digits} argument or the
+    default value if \code{digits = NULL}}
+  \item{quote}{the value of the \code{quote} argument}
+  \item{ftableDisplay}{the value of the \code{display} argument or the
+    default value if \code{align = NULL}}
+  \item{method}{the value of the \code{method} argument}
+  \item{lsep}{the value of the \code{lsep} argument}
+  \item{nChars}{a vector of length 2 giving the number of character rows
+    and the number of character columns}
+
+  For \code{print.xtableFtable} a character string which will produce a
+  formatted table when included in a LaTeX document.
+
+}
+\references{
+  Fairbairns, Robin (2005) \emph{Tables longer than a single page.} The
+  UK List of TeX Frequently Asked Questions on the
+  Web. \url{http://www.tex.ac.uk/cgi-bin/texfaq2html?label=longtab}
+}
+\author{
+  David Scott \email{d.scott@auckland.ac.nz}.
+}
+\note{
+  The functions \code{xtableFtable} and \code{print.xtableFtable} are
+  new and their behaviour may change in the future based on user
+  experience and recommendations.
+
+  It is not recommended that users change the values of \code{align},
+  \code{digits} or \code{align}. First of all, alternative values have
+  not been tested. Secondly, it is most likely that to determine
+  appropriate values for these arguments, users will have to investigate
+  the code for \code{xtableFtable} and/or \code{print.xtableFtable}.
+}
+
+\seealso{
+  \code{\link{ftable}}, \code{\link{print.ftable}},
+  \code{\link{xtable}}, \code{\link{caption}}, \code{\link{label}},
+  \code{\link{align}}, \code{\link{digits}}, \code{\link{display}},
+  \code{\link{formatC}}
+}
+\examples{
+data(mtcars)
+mtcars$cyl <- factor(mtcars$cyl, levels = c("4","6","8"),
+                     labels = c("four","six","eight"))
+tbl <- ftable(mtcars$cyl, mtcars$vs, mtcars$am, mtcars$gear,
+              row.vars = c(2, 4),
+              dnn = c("Cylinders", "V/S", "Transmission", "Gears"))
+xftbl <- xtableFtable(tbl, method = "compact")
+print.xtableFtable(xftbl, booktabs = TRUE)
+xftbl <- xtableFtable(tbl, method = "row.compact")
+print.xtableFtable(xftbl, rotate.colnames = TRUE,
+                   rotate.rownames = TRUE)
+}
+
+\keyword{ category }
+\keyword{ print }
diff --git a/pkg/man/xtableList.Rd b/pkg/man/xtableList.Rd
new file mode 100644 (file)
index 0000000..1682689
--- /dev/null
@@ -0,0 +1,331 @@
+\name{xtableList}\r
+\alias{xtableList}\r
+\alias{print.xtableList}\r
+\r
+\title{\r
+  Create and Export Lists of Tables\r
+}\r
+\description{\r
+  \code{xtableList} creates an object which contains information about\r
+  lists of table which can be used by \code{print.xtableList} to produce\r
+  a character string which when included in a document produces a nicely\r
+  formatted table made up of the information in the individual tables\r
+  which comprised the original list of tables.\r
+}\r
+\usage{\r
+xtableList(x, caption = NULL, label = NULL,\r
+           align = NULL, digits = NULL, display = NULL, ...)\r
+\r
+\method{print}{xtableList}(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
+  caption.width = getOption("xtable.caption.width", NULL),\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 = NULL,\r
+  NA.string = getOption("xtable.NA.string", ""),\r
+  include.rownames = getOption("xtable.include.rownames", TRUE),\r
+  colnames.format = "single",\r
+  only.contents = getOption("xtable.only.contents", FALSE),\r
+  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
+  sanitize.subheadings.function =\r
+    getOption("xtable.sanitize.subheadings.function",\r
+              sanitize.text.function),\r
+  sanitize.message.function =\r
+    getOption("xtable.sanitize.message.function",\r
+              sanitize.text.function),\r
+  math.style.negative = getOption("xtable.math.style.negative", FALSE),\r
+  math.style.exponents = getOption("xtable.math.style.exponents", 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
+  rotate.rownames = getOption("xtable.rotate.rownames", FALSE),\r
+  rotate.colnames = getOption("xtable.rotate.colnames", FALSE),\r
+  booktabs = getOption("xtable.booktabs", FALSE),\r
+  scalebox = getOption("xtable.scalebox", NULL),\r
+  width = getOption("xtable.width", NULL),\r
+  comment = getOption("xtable.comment", TRUE),\r
+  timestamp = getOption("xtable.timestamp", date()),\r
+  ...)\r
+}\r
+\arguments{\r
+  \item{x}{\r
+    For \code{xtableList}, a list of \R objects all of the same class,\r
+    being a class found among \code{methods(xtable)}. The list may also\r
+    have attributes \code{"subheadings"} and \code{"message"}. The\r
+    attribute \code{"subheadings"} should be a character vector of the\r
+    same length as the list \code{x}. The attribute \code{"message"}\r
+    should be a character vector of any length.\r
+    For \code{print.xtableList}, an object of class \code{xtableList}\r
+    produced by a call to \code{xtableList}.}\r
+  \item{caption}{Character vector of length 1 or 2 containing the\r
+    table's caption or title.  If length is 2, the second item is the\r
+    "short caption" used when LaTeX generates a "List of Tables". Set to\r
+    \code{NULL} to suppress the caption.  Default value is \code{NULL}. }\r
+  \item{label}{Character vector of length 1 containing the LaTeX label\r
+    or HTML anchor. Set to \code{NULL} to suppress the label.  Default\r
+    value is \code{NULL}. }\r
+  \item{align}{Character vector of length equal to the number of columns\r
+    of the resulting table, indicating the alignment of the corresponding\r
+    columns.  Also, \code{"|"} may be used to produce vertical lines\r
+    between columns in LaTeX tables, but these are effectively ignored\r
+    when considering the required length of the supplied vector.  If a\r
+    character vector of length one is supplied, it is split as\r
+    \code{strsplit(align, "")[[1]]} before processing. Since the row\r
+    names are printed in the first column, the length of \code{align} is\r
+    one greater than \code{ncol(x)} if \code{x} is a\r
+    \code{data.frame}. Use \code{"l"}, \code{"r"}, and \code{"c"} to\r
+    denote left, right, and center alignment, respectively.  Use\r
+    \code{"p{3cm}"} etc. for a LaTeX column of the specified width. For\r
+    HTML output the \code{"p"} alignment is interpreted as \code{"l"},\r
+    ignoring the width request. Default depends on the class of\r
+    \code{x}. }\r
+  \item{digits}{\r
+    Either \code{NULL}, or a vector of length one, or a vector of length\r
+    equal to the number of columns in the resulting table, indicating\r
+    the number of digits to display in the corresponding columns, or a\r
+    list if length equal to the number of R objects making up \code{x},\r
+    all members being vectors of the same length, either length one or\r
+    of length equal to the number of columns in the resulting table. See\r
+    \sQuote{Details} for further information.}\r
+  \item{display}{\r
+    Either \code{NULL}, or a vector of length one, or a vector of length\r
+    equal to the number of columns in the resulting table, indicating\r
+    the format of the corresponding columns, or a\r
+    list if length equal to the number of R objects making up \code{x},\r
+    all members being vectors of the same length, either length one or\r
+    of length equal to the number of columns in the resulting table. See\r
+    \sQuote{Details} for further information.}\r
+  \item{type}{Type of table to produce. Possible values for \code{type}\r
+    are \code{"latex"} or \code{"html"}.\r
+    Default value is \code{"latex"}.}\r
+  \item{file}{Name of file where the resulting code should be saved.  If\r
+    \code{file=""}, output is displayed on screen.  Note that the\r
+    function also (invisibly) returns a character vector of the results\r
+    (which can be helpful for post-processing).\r
+    Default value is \code{""}.}\r
+  \item{append}{If \code{TRUE} and \code{file!=""}, code will be\r
+    appended to \code{file} instead of overwriting \code{file}.\r
+    Default value is \code{FALSE}.}\r
+  \item{floating}{If \code{TRUE} and \code{type="latex"}, the resulting\r
+    table will be a floating table (using, for example,\r
+    \code{\\begin\{table\}} and \code{\\end\{table\}}).  See\r
+    \code{floating.environment} below.\r
+    Default value is \code{TRUE}. }\r
+  \item{floating.environment}{If \code{floating=TRUE} and\r
+    \code{type="latex"}, the resulting table uses the specified floating\r
+    environment. Possible values include \code{"table"}, \code{"table*"},\r
+    and other floating environments defined in LaTeX packages.\r
+    Default value is \code{"table"}.}\r
+  \item{table.placement}{If \code{floating=TRUE} and\r
+    \code{type="latex"}, the floating table will have placement given by\r
+    \code{table.placement} where \code{table.placement} must be\r
+    \code{NULL} or contain only elements of\r
+    \{"h","t","b","p","!","H"\}.\r
+    Default value is \code{"ht"}.}\r
+  \item{caption.placement}{The caption will be placed at the bottom\r
+    of the table if \code{caption.placement} is \code{"bottom"} and at\r
+    the top of the table if it equals \code{"top"}.\r
+    Default value is \code{"bottom"}.}\r
+  \item{caption.width}{The caption will be placed in a \code{"parbox"}\r
+    of the specified width if \code{caption.width} is not \code{NULL} and\r
+       \code{type="latex"}. Default value is \code{NULL}.}\r
+  \item{latex.environments}{If \code{floating=TRUE} and\r
+    \code{type="latex"}, the specified LaTeX environments (provided as\r
+    a character vector) will enclose the tabular environment.\r
+    Default value is \code{"center"}. }\r
+  \item{tabular.environment}{When \code{type="latex"}, the tabular\r
+    environment that will be used.\r
+    When working with tables that extend more than one page, using\r
+    \code{tabular.environment="longtable"} with the corresponding\r
+    LaTeX package (see Fairbairns, 2005) allows one to typeset them\r
+    uniformly. Note that \code{floating} should be set to\r
+    \code{FALSE} when using the \code{longtable} environment.\r
+    Default value is \code{"tabular"}.}\r
+  \item{size}{A character vector that is inserted just before the\r
+    tabular environment starts. This can be used to set the font size\r
+    and a variety of other table settings. Initial backslashes are\r
+    automatically prefixed, if not supplied by user.\r
+    Default value is \code{NULL}. }\r
+  \item{hline.after}{When \code{type="latex"}, a vector of numbers\r
+    between -1 and the number of rows in the resulting table, inclusive,\r
+    indicating the rows after which a horizontal line should\r
+    appear. Determining row numbers is not straightforward since some\r
+    lines in the resulting table don't enter into the count.  The\r
+    default depends on the value of \code{col.names.format}.}\r
+  \item{NA.string}{String to be used for missing values in table\r
+    entries.\r
+    Default value is \code{""}.}\r
+  \item{include.rownames}{If \code{TRUE} the rows names are\r
+    printed.\r
+    Default value is \code{TRUE}.}\r
+  \item{colnames.format}{Either \code{"single"} or \code{"multiple"}.\r
+    Default is \code{"single"}.}\r
+  \item{only.contents}{If \code{TRUE} only the rows of the\r
+    table are printed.\r
+    Default value is \code{FALSE}. }\r
+  \item{add.to.row}{A list of two components. The first component (which\r
+    should be called 'pos') is a list that contains the position of rows on\r
+    which extra commands should be added at the end. The second\r
+    component (which should be called 'command') is a character vector\r
+    of the same length as the first component, which contains the command\r
+    that should be added at the end of the specified rows.\r
+    Default value is \code{NULL}, i.e. do not add commands.}\r
+  \item{sanitize.text.function}{All non-numeric entries (except row and\r
+    column names) are sanitized in an attempt to remove characters which\r
+    have special meaning for the output format. If\r
+    \code{sanitize.text.function} is not \code{NULL}, it should\r
+    be a function taking a character vector and returning one, and will\r
+    be used for the sanitization instead of the default internal\r
+    function.\r
+    Default value is \code{NULL}.}\r
+  \item{sanitize.rownames.function}{Like the\r
+    \code{sanitize.text.function}, but applicable to row names.\r
+    The default uses the \code{sanitize.text.function}. }\r
+  \item{sanitize.colnames.function}{Like the\r
+    \code{sanitize.text.function}, but applicable to column names.\r
+    The default uses the \code{sanitize.text.function}. }\r
+  \item{sanitize.subheadings.function}{Like the\r
+    \code{sanitize.text.function}, but applicable to subheadings.\r
+    The default uses the \code{sanitize.text.function}. }\r
+  \item{sanitize.message.function}{Like the\r
+    \code{sanitize.text.function}, but applicable to the message.\r
+    The default uses the \code{sanitize.text.function}. }\r
+  \item{math.style.negative}{In a LaTeX table, if \code{TRUE}, then use\r
+    $-$ for the negative sign (as was the behavior prior to version 1.5-3).\r
+    Default value is \code{FALSE}.}\r
+  \item{math.style.exponents}{In a LaTeX table, if \code{TRUE} or\r
+    \code{"$$"}, then use \verb{$5 \times 10^{5}$} for 5e5. If\r
+    \code{"ensuremath"}, then use \verb{\\ensuremath{5 \times 10^{5}}}\r
+    for 5e5. If \code{"UTF-8"} or \code{"UTF-8"}, then use UTF-8 to\r
+    approximate the LaTeX typsetting for 5e5.\r
+    Default value is \code{FALSE}.}\r
+  \item{html.table.attributes}{In an HTML table, attributes associated\r
+    with the \code{<TABLE>} tag.\r
+    Default value is \code{"border=1"}.}\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{TRUE}.}\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 =\r
+      ","))}. The arguments \code{digits} and \code{format} should not be\r
+    included in this list. See details.\r
+    Default value is \code{NULL}.}\r
+  \item{rotate.rownames}{If \code{TRUE}, the row names are displayed\r
+    vertically in LaTeX.\r
+    Default value is \code{FALSE}.}\r
+  \item{rotate.colnames}{If \code{TRUE}, the column names are displayed\r
+    vertically in LaTeX.\r
+    Default value is \code{FALSE}.}\r
+  \item{booktabs}{If \code{TRUE}, the \code{toprule}, \code{midrule} and\r
+    \code{bottomrule} commands from the LaTeX "booktabs" package are used\r
+    rather than \code{hline} for the horizontal line tags. }\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{width}{If not \code{NULL}, the specified value is included in\r
+    parentheses between the tabular environment \code{begin} tag and the\r
+    alignment specification.  This allows specification of the table\r
+    width when using tabular environments such as \code{tabular*} and\r
+    \code{tabularx}.  Note that table width specification is not\r
+    supported with the \code{tabular} or \code{longtable} environments.\r
+    Default value is \code{NULL}.}\r
+  \item{comment}{If \code{TRUE}, the version and timestamp comment is\r
+    included.  Default value is \code{TRUE}. }\r
+  \item{timestamp}{Timestamp to include in LaTeX comment.  Set this\r
+    to \code{NULL} to exclude the timestamp. Default value is\r
+    \code{date()}. }\r
+  \item{\dots}{Additional arguments.  (Currently ignored.)}\r
+}\r
+\details{\r
+  \code{xtableList} produces an object suitable for printing using\r
+  \code{print.xtableList}.\r
+\r
+  The elements of the list \code{x} supplied to \code{xtableList} must\r
+  all have the same structure. When these list items are submitted to\r
+  \code{xtable} the resulting table must have the same number of columns\r
+  with the same column names and type of data.\r
+\r
+  The values supplied to arguments \code{digits} and \code{display},\r
+  must be composed of elements as specified in those same arguments for\r
+  the function \code{\link{xtable}}. See the help for\r
+  \code{\link{xtable}} for details.\r
+\r
+  \code{print.xtableList} produces tables in two different formats\r
+  depending on the value of \code{col.names.format}. If\r
+  \code{col.names.format = "single"}, the resulting table has only a\r
+  single heading row. If \code{col.names.format = "multiple"} there is a\r
+  heading row for each of the subtables making up the complete table.\r
+\r
+  By default if \code{col.names.format = "single"}, there are horizontal\r
+  lines above and below the heading row, and at the end of each\r
+  subtable. If \code{col.names.format = "multiple"}, there are\r
+  horizontal lines above and below each appearance of the heading row,\r
+  and at the end of each subtable.\r
+\r
+  If \code{"subheadings"} is not \code{NULL}, the individual elements of\r
+  this vector (which can include newlines \verb{\\n}) produce a heading\r
+  line or lines for the subtables. When \code{col.names.format =\r
+    "multiple"} these subheadings appear \emph{above} the heading rows.\r
+\r
+  If \code{"message"} is not \code{NULL} the vector produces a line or\r
+  lines at the end of the table.\r
+\r
+  Consult the vignette \sQuote{The \code{xtableList} Gallery} to see\r
+  the behaviour of these functions.\r
+\r
+  Note that at present there is no code for \code{type = "html"}.\r
+}\r
+\value{\r
+  \code{xtableList} produces an object of class\r
+  \code{"xtableList"}. An object of this class is a list of\r
+  \code{"xtable"} objects with some additional attributes. Each element\r
+  of the list can have a \code{"subheading"} attribute. The list can\r
+  also have a \code{"message"} attribute.\r
+\r
+  \code{print.xtableList} produces a character string containing LaTeX\r
+  markup which produces a nicely formatted table comprised of subtables,\r
+  when included in a LaTeX document.\r
+}\r
+\author{\r
+  David Scott \email{d.scott@auckland.ac.nz}.\r
+}\r
+\note{\r
+  The functions \code{xtableList} and \code{print.xtableList} are\r
+  new and their behaviour may change in the future based on user\r
+  experience and recommendations.\r
+}\r
+\r
+\r
+\seealso{\r
+  \code{\link{xtable}}, \code{\link{caption}}, \code{\link{label}},\r
+  \code{\link{align}}, \code{\link{digits}}, \code{\link{display}},\r
+  \code{\link{formatC}}, \code{\link{print.xtable}}.\r
+}\r
+\examples{\r
+data(mtcars)\r
+mtcars <- mtcars[, 1:6]\r
+mtcarsList <- split(mtcars, f = mtcars$cyl)\r
+attr(mtcarsList, "subheadings") <- paste0("Number of cylinders = ",\r
+                                          names(mtcarsList))\r
+attr(mtcarsList, "message") <- c("Line 1 of Message",\r
+                                 "Line 2 of Message")\r
+xList <- xtableList(mtcarsList)\r
+print.xtableList(xList)\r
+print.xtableList(xList, colnames.format = "multiple")\r
+}\r
+\keyword{ print }\r
diff --git a/pkg/man/xtableMatharray.Rd b/pkg/man/xtableMatharray.Rd
new file mode 100644 (file)
index 0000000..c050411
--- /dev/null
@@ -0,0 +1,105 @@
+\name{xtableMatharray}\r
+\alias{xtableMatharray}\r
+\r
+\title{\r
+ Create LaTeX Mathematical Array\r
+}\r
+\description{\r
+  Convert an array of numbers or mathematical expressions into an\r
+ \code{xtableMatharray} object so it can be printed. A convenience\r
+ function to enable the printing of arrays in mathematical expressions\r
+ in LaTeX\r
+}\r
+\usage{\r
+xtableMatharray(x, caption = NULL, label = NULL, align = NULL,\r
+                digits = NULL, display = NULL, auto = FALSE, ...)\r
+}\r
+\arguments{\r
+  \item{x}{A numeric or character matrix.}\r
+  \item{caption}{Character vector of length 1 or 2 containing the\r
+    table's caption or title.  If length is 2, the second item is the\r
+    "short caption" used when LaTeX generates a "List of Tables". Set to\r
+    \code{NULL} to suppress the caption.  Default value is \code{NULL}.\r
+    Included here only for consistency with \code{xtable} methods. Not\r
+    expected to be of use.}\r
+  \item{label}{Character vector of length 1 containing the LaTeX\r
+    label. Set to \code{NULL} to suppress the label.\r
+    Default value is \code{NULL}. }\r
+  \item{align}{Character vector of length equal to the number of columns\r
+    of the resulting table, indicating the alignment of the corresponding\r
+    columns.  Also, \code{"|"} may be used to produce vertical lines\r
+    between columns in LaTeX tables, but these are effectively ignored\r
+    when considering the required length of the supplied vector.  If a\r
+    character vector of length one is supplied, it is split as\r
+    \code{strsplit(align, "")[[1]]} before processing. Since the row\r
+    names are printed in the first column, the length of \code{align} is\r
+    one greater than \code{ncol(x)} if \code{x} is a\r
+    \code{data.frame}. Use \code{"l"}, \code{"r"}, and \code{"c"} to\r
+    denote left, right, and center alignment, respectively.  Use\r
+    \code{"p{3cm}"} etc. for a LaTeX column of the specified width. For\r
+    HTML output the \code{"p"} alignment is interpreted as \code{"l"},\r
+    ignoring the width request. Default depends on the class of\r
+    \code{x}. }\r
+  \item{digits}{Numeric vector of length equal to one (in which case it\r
+    will be replicated as necessary) or to the number of columns of the\r
+    resulting table \bold{or} matrix of the same size as the resulting\r
+    table, indicating the number of digits to display in the\r
+    corresponding columns. Since the row names are printed in the first\r
+    column, the length of the vector \code{digits} or the number of\r
+    columns of the matrix \code{digits} is one greater than\r
+    \code{ncol(x)} if \code{x} is a \code{data.frame}. Default depends\r
+    on the class of \code{x}. If values of \code{digits} are negative,\r
+    the corresponding values of \code{x} are displayed in scientific\r
+    format with \code{abs(digits)} digits.}\r
+  \item{display}{\r
+    Character vector of length equal to the number of columns of the\r
+    resulting table, indicating the format for the corresponding columns.\r
+    Since the row names are printed in the first column, the length of\r
+    \code{display} is one greater than \code{ncol(x)} if \code{x} is a\r
+    \code{data.frame}.  These values are passed to the \code{formatC}\r
+    function.  Use \code{"d"} (for integers), \code{"f"}, \code{"e"},\r
+    \code{"E"}, \code{"g"}, \code{"G"}, \code{"fg"} (for reals), or\r
+    \code{"s"} (for strings).  \code{"f"} gives numbers in the usual\r
+    \code{xxx.xxx} format; \code{"e"} and \code{"E"} give\r
+    \code{n.ddde+nn} or \code{n.dddE+nn} (scientific format); \code{"g"}\r
+    and \code{"G"} put \code{x[i]} into scientific format only if it\r
+    saves space to do so.  \code{"fg"} uses fixed format as \code{"f"},\r
+    but \code{digits} as number of \emph{significant} digits.  Note that\r
+    this can lead to quite long result strings.  Default depends on the\r
+    class of \code{x}.}\r
+  \item{auto}{\r
+    Logical, indicating whether to apply automatic format when no value\r
+    is passed to \code{align}, \code{digits}, or \code{display}. This\r
+    \sQuote{autoformat} (based on \code{xalign}, \code{xdigits}, and\r
+    \code{xdisplay}) can be useful to quickly format a typical\r
+    \code{matrix} or \code{data.frame}. Default value is \code{FALSE}.}\r
+  \item{...}{Additional arguments.  (Currently ignored.)}\r
+}\r
+\details{\r
+  This function is only usable for production of LaTeX documents, not\r
+  HTML.\r
+\r
+  Creates an object of class\r
+ \code{c("xtableMatharray","xtable","data.frame")}, to ensure that it is\r
+ printed by the print method \code{print.xtableMatharray}.\r
+}\r
+\value{\r
+ An object of class \code{c("xtableMatharray","xtable","data.frame")}.\r
+}\r
+\r
+\author{\r
+  David Scott <d.scott@auckland.ac.nz>\r
+}\r
+\seealso{\r
+\code{\link{print.xtableMatharray}}\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
+mth <- xtableMatharray(V)\r
+class(mth)\r
+str(mth)\r
+unclass(mth)\r
+}\r
+\keyword{ print }\r
diff --git a/pkg/tests/test.matharray.R b/pkg/tests/test.matharray.R
new file mode 100644 (file)
index 0000000..172ff92
--- /dev/null
@@ -0,0 +1,37 @@
+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)
+### Simple test of print.xtableMatharray
+print.xtableMatharray(xtable(V, display = rep("E", 4)))
+
+class(V) <- c("xtableMatharray")
+class(V)
+
+### Test without any additional arguments
+mth <- xtableMatharray(V)
+str(mth)
+print(mth)
+
+### Test with arguments to xtable
+mth <- xtableMatharray(V, display = rep("E", 4))
+str(mth)
+print(mth)
+
+mth <- xtableMatharray(V, digits = 6)
+str(mth)
+print(mth)
+
+### Test with additional print.xtableMatharray arguments
+mth <- xtableMatharray(V, digits = 6)
+str(mth)
+print(mth, format.args = list(decimal.mark = ","))
+print(mth, scalebox = 0.5)
+print(mth, comment = TRUE)
+print(mth, timestamp = "2000-01-01")
+print(mth, comment = TRUE, timestamp = "2000-01-01")
+
+
+
+
+
diff --git a/pkg/tests/test.xtable.xtableFtable.R b/pkg/tests/test.xtable.xtableFtable.R
new file mode 100644 (file)
index 0000000..5ac399f
--- /dev/null
@@ -0,0 +1,24 @@
+### Test code for xtableFtable function
+### David Scott, <d.scott@auckland.ac.nz>, 2016-01-14
+library(xtable)
+
+
+tbl <- ftable(mtcars$cyl, mtcars$vs, mtcars$am, mtcars$gear, row.vars = c(2, 4),
+              dnn = c("Cylinders", "V/S", "Transmission", "Gears"))
+
+## debug(xtableFtable)
+xftbl <- xtableFtable(tbl)
+str(xftbl)
+unclass(xftbl)
+print.xtableFtable(xftbl)
+xftbl <- xtableFtable(tbl, method = "row.compact")
+print.xtableFtable(xftbl)
+xftbl <- xtableFtable(tbl, method = "col.compact")
+print.xtableFtable(xftbl)
+xftbl <- xtableFtable(tbl, method = "compact")
+print.xtableFtable(xftbl)
+## debug(print.xtableFtable)
+## undebug(print.xtableFtable)
+## debug(print.xtable)
+## undebug(print.xtable)
+
diff --git a/pkg/vignettes/OtherPackagesGallery.Rnw b/pkg/vignettes/OtherPackagesGallery.Rnw
new file mode 100644 (file)
index 0000000..1676da4
--- /dev/null
@@ -0,0 +1,328 @@
+%\VignetteIndexEntry{xtable Other Packages Gallery}\r
+%\VignetteDepends{xtable, spdep, splm, sphet}\r
+%\VignetteKeywords{LaTeX, HTML, table}\r
+%\VignettePackage{xtable}\r
+% !Rnw weave = knitr\r
+% \VignetteEngine{knitr::knitr}\r
+%**************************************************************************\r
+\documentclass{article}\r
+\usepackage[a4paper, height=24cm]{geometry} % geometry first\r
+\usepackage{array}\r
+\usepackage{booktabs}\r
+\usepackage{longtable}\r
+\usepackage{parskip}\r
+\usepackage{rotating}\r
+\usepackage{tabularx}\r
+\usepackage{titlesec}\r
+\usepackage{hyperref} % hyperref last\r
+\titleformat\subsubsection{\bfseries\itshape}{}{0pt}{}\r
+\newcommand\p{\vspace{2ex}}\r
+\newcommand\code[1]{\texttt{#1}}\r
+\newcommand\pkg[1]{\textbf{#1}}\r
+\setcounter{tocdepth}{2}\r
+\begin{document}\r
+\r
+\title{\bfseries\Large The Other Packages Gallery}\r
+\author{\bfseries David J. Scott}\r
+\maketitle\r
+\r
+\tableofcontents\r
+\r
+\newpage\r
+\r
+\section{Introduction}\r
+This document represents a test of the functions in \pkg{xtable} which\r
+deal with other packages.\r
+\r
+<<set, include=FALSE>>=\r
+library(knitr)\r
+opts_chunk$set(fig.path = 'Figures/other', debug = TRUE, echo = TRUE)\r
+opts_chunk$set(out.width = '0.9\\textwidth')\r
+@\r
+\r
+The first step is to load the package and set some options for this document.\r
+<<package, results='asis'>>=\r
+library(xtable)\r
+options(xtable.floating = FALSE)\r
+options(xtable.timestamp = "")\r
+options(width = 60)\r
+set.seed(1234)\r
+@\r
+\r
+\section{The packages \pkg{spdep}, \pkg{splm}, and \pkg{sphet}}\r
+\r
+Code for supporting these packages and most of the examples used in\r
+this section was originally provided by Martin Gubri\r
+(\url{martin.gubri@framasoft.org}).\r
+\r
+\subsection{The package \pkg{spdep}}\r
+\label{sec:package-pkgspdep}\r
+\r
+First load the package and create some objects.\r
+<<dataspdep>>=\r
+library(spdep)\r
+data("oldcol", package = "spdep")\r
+\r
+data.in.sample <- COL.OLD[1:44,]\r
+data.out.of.sample <- COL.OLD[45:49,]\r
+\r
+listw.in.sample <- nb2listw(subset(COL.nb, !(1:49 %in% 45:49)))\r
+listw.all.sample <- nb2listw(COL.nb)\r
+\r
+COL.lag.eig <- lagsarlm(CRIME ~ INC + HOVAL, data = data.in.sample,\r
+                        listw.in.sample)\r
+class(COL.lag.eig)\r
+COL.errW.GM <- GMerrorsar(CRIME ~ INC + HOVAL, data = data.in.sample,\r
+                          listw.in.sample, returnHcov = TRUE)\r
+class(COL.errW.GM)\r
+COL.lag.stsls <- stsls(CRIME ~ INC + HOVAL, data = data.in.sample,\r
+                       listw.in.sample)\r
+class(COL.lag.stsls)\r
+\r
+p1 <- predict(COL.lag.eig, newdata = data.out.of.sample,\r
+              listw = listw.all.sample)\r
+class(p1)\r
+p2 <- predict(COL.lag.eig, newdata = data.out.of.sample,\r
+              pred.type = "trend", type = "trend")\r
+#type option for retrocompatibility with spdep 0.5-92\r
+class(p2)\r
+\r
+imp.exact <- impacts(COL.lag.eig, listw = listw.in.sample)\r
+class(imp.exact)\r
+imp.sim <- impacts(COL.lag.eig, listw = listw.in.sample, R = 200)\r
+class(imp.sim)\r
+@ %def\r
+\r
+\r
+\subsubsection{\code{sarlm} objects}\r
+\label{sec:codesarlm-objects}\r
+\r
+There is an \code{xtable} method for objects of this type.\r
+<<xtablesarlm, results = 'asis'>>=\r
+xtable(COL.lag.eig)\r
+@ %def\r
+\r
+The method for \code{xtable} actually uses the summary of the object,\r
+and an identical result is obtained when using the summary of the\r
+object, even if the summary contains more additional information.\r
+\r
+<<xtablesarlmsumm, results = 'asis'>>=\r
+xtable(summary(COL.lag.eig, correlation = TRUE))\r
+@ %def\r
+\r
+This same pattern applies to the other objects from this group of packages.\r
+\r
+Note that additional prettying of the resulting table is possible, as\r
+for any table produced using \code{xtable}. For example using the\r
+\pkg{booktabs} package we get:\r
+\r
+<<xtablesarlmbooktabs, results = 'asis'>>=\r
+print(xtable(COL.lag.eig), booktabs = TRUE)\r
+@ %def\r
+\r
+\subsubsection{\code{gmsar} objects}\r
+\label{sec:codegmsar-objects}\r
+\r
+\r
+<<xtablegmsar, results = 'asis'>>=\r
+xtable(COL.errW.GM)\r
+@ %def\r
+\r
+\subsubsection{\code{stsls} objects}\r
+\label{sec:codestsls-objects}\r
+\r
+\r
+<<xtablestsls, results = 'asis'>>=\r
+xtable(COL.lag.stsls)\r
+@ %def\r
+\r
+\subsubsection{\code{sarlm.pred} objects}\r
+\label{sec:codesarlmpred-objects}\r
+\r
+\code{xtable} has a method for predictions of \code{sarlm} models.\r
+\r
+<<xtablesarlmpred, results = 'asis'>>=\r
+xtable(p1)\r
+@ %def\r
+\r
+This method transforms the \code{sarlm.pred} objects into data frames,\r
+allowing any number of attributes vectors which may vary according to\r
+predictor types.\r
+\r
+<<xtablesarlmpred2, results = 'asis'>>=\r
+xtable(p2)\r
+@ %def\r
+\r
+\subsubsection{\code{lagImpact} objects}\r
+\label{sec:codelagimpact-objects}\r
+\r
+The \code{xtable} method returns the values of direct, indirect and\r
+total impacts for all the variables in the model. The class\r
+\code{lagImpact} has two different sets of attributes according to if\r
+simulations are used. But the \code{xtable} method always returns the\r
+three components of the non-simulation case.\r
+\r
+<<xtablelagimpactexact, results = 'asis'>>=\r
+xtable(imp.exact)\r
+@ %def\r
+\r
+\p\r
+<<xtablelagimpactmcmc, results = 'asis'>>=\r
+xtable(imp.sim)\r
+@ %def\r
+\r
+\r
+\subsubsection{\code{spautolm} objects}\r
+\label{sec:codespautolm-objects}\r
+\r
+The need for an \code{xtable} method for \code{spautolm} was expressed\r
+by Guido Schulz (\url{schulzgu@student.hu-berlin.de}), who also\r
+provided an example of an object of this type. The required code was\r
+implemented by David Scott (\url{d.scott@auckland.ac.nz}).\r
+\r
+First create an object of the required type.\r
+\r
+<<minimalexample, results = 'hide'>>=\r
+library(spdep)\r
+example(NY_data)\r
+spautolmOBJECT <- spautolm(Z ~ PEXPOSURE + PCTAGE65P,data = nydata,\r
+                           listw = listw_NY, family = "SAR",\r
+                           method = "eigen", verbose = TRUE)\r
+summary(spautolmOBJECT, Nagelkerke = TRUE)\r
+@ %def\r
+\r
+\p\r
+<<spautolmclass>>=\r
+class(spautolmOBJECT)\r
+@ %def\r
+\r
+\r
+<<xtablespautolm, results = 'asis'>>=\r
+xtable(spautolmOBJECT,\r
+       display = c("s",rep("f", 3), "e"), digits = 4)\r
+@ %def\r
+\r
+\r
+\r
+\subsection{The package \pkg{splm}}\r
+\label{sec:package-pkgsplm}\r
+\r
+First load the package and create some objects.\r
+<<datasplm>>=\r
+library(splm)\r
+data("Produc", package = "plm")\r
+data("usaww",  package = "splm")\r
+fm <- log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp\r
+respatlag <- spml(fm, data = Produc, listw = mat2listw(usaww),\r
+                   model="random", spatial.error="none", lag=TRUE)\r
+class(respatlag)\r
+GM <- spgm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data = Produc,\r
+           listw = usaww, moments = "fullweights", spatial.error = TRUE)\r
+class(GM)\r
+\r
+imp.spml <- impacts(respatlag, listw = mat2listw(usaww, style = "W"), time = 17)\r
+class(imp.spml)\r
+@ %def\r
+\r
+\r
+\subsubsection{\code{splm} objects}\r
+\label{sec:codesplm-objects}\r
+\r
+<<xtablesplm, results = 'asis'>>=\r
+xtable(respatlag)\r
+@ %def\r
+\r
+\r
+\p\r
+<<xtablesplm1, results = 'asis'>>=\r
+xtable(GM)\r
+@ %def\r
+\r
+\r
+\r
+The \code{xtable} method works the same on impacts of \code{splm} models.\r
+\r
+<<xtablesplmimpacts, results = 'asis'>>=\r
+xtable(imp.spml)\r
+@ %def\r
+\r
+\subsection{The package \pkg{sphet}}\r
+\label{sec:package-pkgsphet}\r
+\r
+First load the package and create some objects.\r
+<<datasphet>>=\r
+library(sphet)\r
+data("columbus", package = "spdep")\r
+listw <- nb2listw(col.gal.nb)\r
+data("coldis", package = "sphet")\r
+res.stsls <- stslshac(CRIME ~ HOVAL + INC, data = columbus, listw = listw,\r
+                      distance = coldis, type = 'Triangular')\r
+class(res.stsls)\r
+\r
+res.gstsls <- gstslshet(CRIME ~ HOVAL + INC, data = columbus, listw = listw)\r
+class(res.gstsls)\r
+\r
+imp.gstsls <- impacts(res.gstsls, listw = listw)\r
+class(imp.gstsls)\r
+@ %def\r
+\r
+\r
+\subsubsection{\code{sphet} objects}\r
+\label{sec:codesphet-objects}\r
+\r
+<<xtablesphet, results = 'asis'>>=\r
+xtable(res.stsls)\r
+@ %def\r
+\r
+\p\r
+<<xtablesphet1, results = 'asis'>>=\r
+xtable(res.gstsls)\r
+@ %def\r
+\r
+\r
+\code{sphet} also provides a method for computing impacts.\r
+\r
+<<xtablesphetimpacts, results = 'asis'>>=\r
+xtable(imp.gstsls)\r
+@ %def\r
+\r
+\section{The \pkg{zoo} package}\r
+\label{sec:pkgzoo-package}\r
+\r
+\r
+<<zoo, results = 'asis'>>=\r
+library(zoo)\r
+xDate <- as.Date("2003-02-01") + c(1, 3, 7, 9, 14) - 1\r
+as.ts(xDate)\r
+x <- zoo(rnorm(5), xDate)\r
+xtable(x)\r
+@ %def\r
+\r
+\r
+\p\r
+\r
+<<zoots, results = 'asis'>>=\r
+tempTs <- ts(cumsum(1 + round(rnorm(100), 0)),\r
+              start = c(1954, 7), frequency = 12)\r
+tempTable <- xtable(tempTs, digits = 0)\r
+tempTable\r
+tempZoo <- as.zoo(tempTs)\r
+xtable(tempZoo, digits = 0)\r
+@ %def\r
+\r
+\r
+\section{The \pkg{survival} package}\r
+\label{sec:pkgsurvival-package}\r
+\r
+\r
+<<survival, results = 'asis'>>=\r
+library(survival)\r
+test1 <- list(time=c(4,3,1,1,2,2,3),\r
+              status=c(1,1,1,0,1,1,0),\r
+              x=c(0,2,1,1,1,0,0),\r
+              sex=c(0,0,0,0,1,1,1))\r
+coxFit <- coxph(Surv(time, status) ~ x + strata(sex), test1)\r
+xtable(coxFit)\r
+@ %def\r
+\r
+\end{document}\r
diff --git a/pkg/vignettes/listOfTablesGallery.Rnw b/pkg/vignettes/listOfTablesGallery.Rnw
new file mode 100644 (file)
index 0000000..5d20236
--- /dev/null
@@ -0,0 +1,267 @@
+%\VignetteIndexEntry{xtable List of Tables Gallery}\r
+%\VignetteDepends{xtable, lsmeans}\r
+%\VignetteKeywords{LaTeX, HTML, table}\r
+%\VignettePackage{xtable}\r
+% !Rnw weave = knitr\r
+% \VignetteEngine{knitr::knitr}\r
+%**************************************************************************\r
+\documentclass{article}\r
+\usepackage[a4paper,height=24cm]{geometry} % geometry first\r
+\usepackage{array}\r
+\usepackage{booktabs}\r
+\usepackage{longtable}\r
+\usepackage{parskip}\r
+\usepackage{rotating}\r
+\usepackage{tabularx}\r
+\usepackage{titlesec}\r
+\usepackage{hyperref} % hyperref last\r
+\titleformat\subsubsection{\bfseries\itshape}{}{0pt}{}\r
+\newcommand\p{\vspace{2ex}}\r
+\newcommand\code[1]{\texttt{#1}}\r
+\newcommand\pkg[1]{\textbf{#1}}\r
+\setcounter{tocdepth}{2}\r
+\begin{document}\r
+\r
+\title{\bfseries\Large The \code{xtableList} Gallery}\r
+\author{\bfseries David J. Scott}\r
+\maketitle\r
+\r
+\tableofcontents\r
+\r
+\newpage\r
+\r
+\section{Introduction}\r
+This document represents a test of the functions in \pkg{xtable} which\r
+deal with lists of dataframes.\r
+\r
+<<set, include=FALSE>>=\r
+library(knitr)\r
+opts_chunk$set(fig.path='Figures/list', debug=TRUE, echo=TRUE)\r
+opts_chunk$set(out.width='0.9\\textwidth')\r
+@\r
+\r
+The first step is to load the package and set some options for this document.\r
+<<package, results='asis'>>=\r
+library(xtable)\r
+options(xtable.floating = FALSE)\r
+options(xtable.timestamp = "")\r
+options(width = 60)\r
+@\r
+\r
+\r
+Next we create a list of dataframes with attributes.\r
+\r
+<<data>>=\r
+require(xtable)\r
+data(mtcars)\r
+mtcars <- mtcars[, 1:6]\r
+mtcarsList <- split(mtcars, f = mtcars$cyl)\r
+### Reduce the size of the list elements\r
+mtcarsList[[1]] <- mtcarsList[[1]][1,]\r
+mtcarsList[[2]] <- mtcarsList[[2]][1:2,]\r
+mtcarsList[[3]] <- mtcarsList[[3]][1:3,]\r
+attr(mtcarsList, "subheadings") <- paste0("Number of cylinders = ",\r
+                                          names(mtcarsList))\r
+attr(mtcarsList, "message") <- c("Line 1 of Message",\r
+                                 "Line 2 of Message")\r
+str(mtcarsList)\r
+attributes(mtcarsList)\r
+@ %def\r
+\r
+Now create a list of \code{xtable} objects.\r
+\r
+\r
+<<xtablelist>>=\r
+xList <- xtableList(mtcarsList)\r
+str(xList)\r
+@ %def\r
+\r
+Create an alternative version where the lists have different values\r
+for \code{digits}.\r
+\r
+\r
+<<xtablelist1>>=\r
+xList1 <- xtableList(mtcarsList, digits = c(0,2,0,0,0,1,2))\r
+str(xList1)\r
+@ %def\r
+\r
+<<xtablelist2>>=\r
+xList2 <- xtableList(mtcarsList, digits = c(0,2,0,0,0,1,2),\r
+                            caption = "Caption to List",\r
+                            label = "tbl:xtableList")\r
+str(xList2)\r
+@ %def\r
+\r
+Further versions with no subheadings, and no message\r
+\r
+<<xtablelist3>>=\r
+attr(mtcarsList, "subheadings") <- NULL\r
+xList3 <- xtableList(mtcarsList)\r
+str(xList3)\r
+@ %def\r
+\r
+<<xtablelist4>>=\r
+attr(mtcarsList, "message") <- NULL\r
+xList4 <- xtableList(mtcarsList)\r
+str(xList4)\r
+@ %def\r
+\r
+\newpage\r
+\r
+\section{Single Column Names}\r
+\label{sec:single-column-names}\r
+\r
+Print the list of \code{xtable} objects with a single header of the\r
+column names.\r
+\r
+First the default.\r
+\r
+\r
+<<singledefault, results='asis'>>=\r
+print.xtableList(xList)\r
+@ %def\r
+\r
+Booktabs should work.\r
+<<singlebooktabs, results='asis'>>=\r
+print.xtableList(xList, booktabs = TRUE)\r
+@ %def\r
+\r
+With digits being specified.\r
+<<singlebooktabs1, results='asis'>>=\r
+print.xtableList(xList1, booktabs = TRUE)\r
+@ %def\r
+\r
+Row and column names, subheadings, and the message can be sanitized.\r
+\r
+<<sanitize>>=\r
+large <- function(x){\r
+  paste0('{\\Large{\\bfseries ', x, '}}')\r
+}\r
+italic <- function(x){\r
+  paste0('{\\emph{ ', x, '}}')\r
+}\r
+bold <- function(x){\r
+  paste0('{\\bfseries ', x, '}')\r
+}\r
+red <- function(x){\r
+  paste0('{\\color{red} ', x, '}')\r
+}\r
+@ %def\r
+\r
+\r
+<<sanitizesingle, results='asis'>>=\r
+print.xtableList(xList,\r
+                 sanitize.rownames.function = italic,\r
+                 sanitize.colnames.function = large,\r
+                 sanitize.subheadings.function = bold,\r
+                 sanitize.message.function = red,\r
+                 booktabs = TRUE)\r
+@ %def\r
+\r
+A label and caption can be added.\r
+<<singlecaption, results='asis'>>=\r
+print.xtableList(xList2, floating = TRUE)\r
+@ %def\r
+\r
+Rotated column names?\r
+<<singlerotated, results='asis'>>=\r
+print.xtableList(xList, rotate.colnames = TRUE)\r
+@ %def\r
+\r
+No subheadings?\r
+<<nosubheadings, results='asis'>>=\r
+print.xtableList(xList3)\r
+@ %def\r
+\r
+No message?\r
+<<nomessage, results='asis'>>=\r
+print.xtableList(xList4)\r
+@ %def\r
+\r
+\r
+\section{Multiple Column Names}\r
+\label{sec:multiple-column-names}\r
+\r
+Print the list of \code{xtable} objects with multiple headers of the\r
+column names.\r
+\r
+First the default with multiple column name headers.\r
+\r
+<<multipledefault, results='asis'>>=\r
+print.xtableList(xList, colnames.format = "multiple")\r
+@ %def\r
+\r
+Using booktabs:\r
+\r
+<<multiplebooktabs, results='asis'>>=\r
+print.xtableList(xList, colnames.format = "multiple",\r
+                 booktabs = TRUE)\r
+@ %def\r
+\r
+With sanitization.\r
+<<sanitizemultiple, results='asis'>>=\r
+print.xtableList(xList, colnames.format = "multiple",\r
+                 sanitize.rownames.function = italic,\r
+                 sanitize.colnames.function = large,\r
+                 sanitize.subheadings.function = bold,\r
+                 sanitize.message.function = red,                 \r
+                 booktabs = TRUE)\r
+@ %def\r
+\r
+A label and caption can be added.\r
+<<multiplecaption, results='asis'>>=\r
+print.xtableList(xList2, colnames.format = "multiple",\r
+                 floating = TRUE)\r
+@ %def\r
+\r
+Rotated column names?\r
+<<multiplerotated, results='asis'>>=\r
+print.xtableList(xList, colnames.format = "multiple",\r
+                 rotate.colnames = TRUE)\r
+@ %def\r
+\r
+No subheadings?\r
+<<multiplenosubheadings, results='asis'>>=\r
+print.xtableList(xList3, colnames.format = "multiple")\r
+@ %def\r
+\r
+No message?\r
+<<multiplenomessage, results='asis'>>=\r
+print.xtableList(xList4, colnames.format = "multiple")\r
+@ %def\r
+\r
+\section{lsmeans}\r
+\label{sec:lsmeans}\r
+\r
+Summaries from the \code{lsmeans} function from the \pkg{lsmeans}\r
+package can easily be produced using the function\r
+\code{xtableLSMeans}. This function produces a list of \pkg{xtable}\r
+objects.\r
+\r
+\r
+<<lsmeans>>=\r
+library(lsmeans)\r
+warp.lm <- lm(breaks ~ wool*tension, data = warpbreaks)\r
+warp.lsm <- lsmeans(warp.lm, ~ tension | wool)\r
+warp.sum <- summary(warp.lsm, adjust = "mvt")\r
+warp.xtblList <- xtableLSMeans(warp.sum, digits = c(0,0,2,2,0,2,2))\r
+str(warp.xtblList)\r
+@ %def\r
+\r
+<<lsmeansstr>>=\r
+print.xtableList(warp.xtblList, colnames.format = "multiple",\r
+                 include.rownames = FALSE)\r
+@ %def\r
+<<lsmeanstable, results='asis'>>=\r
+print.xtableList(warp.xtblList, colnames.format = "multiple",\r
+                 include.rownames = FALSE)\r
+@ %def\r
+\p\r
+<<lsmeansbooktabs, results='asis'>>=\r
+print.xtableList(warp.xtblList, colnames.format = "multiple",\r
+                 booktabs = TRUE,\r
+                 include.rownames = FALSE)\r
+@ %def\r
+\r
+\r
+\end{document}\r
index a3897caf539b605201bac65b2772cabd20ff42df..c618d491a4d77fc84f946612af9c14efcdb7e621 100644 (file)
@@ -38,12 +38,14 @@ regression check for the package.
 <<include=FALSE>>=\r
 library(knitr)\r
 opts_chunk$set(fig.path='figdir/fig', debug=TRUE, echo=TRUE)\r
+set.seed(1234)\r
 @\r
 \r
 The first step is to load the package and set an option for this document.\r
 <<results='asis'>>=\r
 library(xtable)\r
 options(xtable.floating = FALSE)\r
+options(xtable.timestamp = "")\r
 @\r
 \r
 \section{Gallery}\r
@@ -83,6 +85,36 @@ fm2b <- lm(tlimth ~ ethnicty, data = tli)
 xtable(anova(fm2b, fm2))\r
 @\r
 \r
+\subsubsection{Anova list}\r
+\r
+<<aovlist>>=\r
+Block <- gl(8, 4)\r
+A <- factor(c(0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,\r
+              0,1,0,1,0,1,0,1,0,1,0,1))\r
+B <- factor(c(0,0,1,1,0,0,1,1,0,1,0,1,1,0,1,0,0,0,1,1,\r
+              0,0,1,1,0,0,1,1,0,0,1,1))\r
+C <- factor(c(0,1,1,0,1,0,0,1,0,0,1,1,0,0,1,1,0,1,0,1,\r
+              1,0,1,0,0,0,1,1,1,1,0,0))\r
+Yield <- c(101, 373, 398, 291, 312, 106, 265, 450, 106, 306, 324, 449,\r
+           272, 89, 407, 338, 87, 324, 279, 471, 323, 128, 423, 334,\r
+           131, 103, 445, 437, 324, 361, 302, 272)\r
+aovdat <- data.frame(Block, A, B, C, Yield)\r
+\r
+old <- getOption("contrasts")\r
+options(contrasts = c("contr.helmert", "contr.poly"))\r
+(fit <- aov(Yield ~ A*B*C + Error(Block), data = aovdat))\r
+class(fit)\r
+summary(fit)\r
+options(contrasts = old)\r
+@\r
+\r
+\p\r
+\r
+<<xtableaovlist, results='asis'>>=\r
+xtable(fit)\r
+@\r
+\r
+\r
 \newpage\r
 \subsection{glm}\r
 <<results='asis'>>=\r
@@ -121,6 +153,87 @@ temp.table <- xtable(temp.ts, digits = 0)
 temp.table\r
 @\r
 \r
+\subsection{Flat tables}\r
+\label{sec:flat-tables}\r
+\r
+See the \textbf{Details} section of the help for \code{ftable} for a\r
+description of these tables, which are flat versions of\r
+multi-dimensional contingency tables. They require special methods to\r
+enable them to be printed using \pkg{xtable}\r
+\r
+\r
+<<ftable>>=\r
+data(mtcars)\r
+mtcars$cyl <- factor(mtcars$cyl, levels = c("4","6","8"),\r
+                     labels = c("four","six","eight"))\r
+tbl <- ftable(mtcars$cyl, mtcars$vs, mtcars$am, mtcars$gear,\r
+              row.vars = c(2, 4),\r
+              dnn = c("Cylinders", "V/S", "Transmission", "Gears"))\r
+tbl\r
+@ %def\r
+\r
+Here is the \LaTeX{} produced:\r
+\r
+<<ftablecheck>>=\r
+xftbl <- xtableFtable(tbl, method = "compact")\r
+print.xtableFtable(xftbl, booktabs = TRUE)\r
+@ %def\r
+\r
+And here is a basic flat table:\r
+\r
+<<ftable1, results = 'asis'>>=\r
+xftbl <- xtableFtable(tbl)\r
+print.xtableFtable(xftbl)\r
+@ %def\r
+\r
+This illustrates the \code{method} argument:\r
+\r
+<<ftable2, results = 'asis'>>=\r
+xftbl <- xtableFtable(tbl, method = "col.compact")\r
+print.xtableFtable(xftbl, rotate.rownames = TRUE)\r
+@ %def\r
+\r
+Booktabs is incompatible with vertical lines in tables, so the\r
+vertical dividing line is removed.\r
+\r
+<<ftable3, results = 'asis'>>=\r
+xftbl <- xtableFtable(tbl, method = "compact")\r
+print.xtableFtable(xftbl, booktabs = TRUE)\r
+@ %def\r
+\p\r
+\r
+Row and column variable names can be formatted specially using\r
+sanitization, and row and column variable names and labels can be\r
+rotated.\r
+\r
+If special formatting is required for row and column labels, that can\r
+be done as a workaround by redefining the data and associated labels.\r
+\r
+<<ftable4, results = 'asis'>>=\r
+italic <- function(x){\r
+  paste0('{\\emph{', x, '}}')\r
+}\r
+mtcars$cyl <- factor(mtcars$cyl, levels = c("four","six","eight"),\r
+                     labels = c("four",italic("six"),"eight"))\r
+large <- function(x){\r
+  paste0('{\\Large ', x, '}')\r
+}\r
+bold <- function(x){\r
+  paste0('{\\bfseries ', x, '}')\r
+}\r
+tbl <- ftable(mtcars$cyl, mtcars$vs, mtcars$am, mtcars$gear,\r
+              row.vars = c(2, 4),\r
+              dnn = c("Cylinders", "V/S", "Transmission", "Gears"))\r
+xftbl <- xtableFtable(tbl, method = "row.compact")\r
+print.xtableFtable(xftbl,\r
+                   sanitize.rownames.function = large,\r
+                   sanitize.colnames.function = bold,\r
+                   rotate.colnames = TRUE,\r
+                   rotate.rownames = TRUE)\r
+@ %def\r
+\r
+\r
+\r
 \newpage\r
 \r
 <<include=FALSE>>=\r
@@ -145,11 +258,12 @@ temp.table
 \r
 \section{Automatic formatting}\r
 \subsection{Suggest alignment, digits, and display}\r
-The functions \code{xalign}, \code{xdigits}, and \code{xdisplay} are useful for\r
-formatting tables in a sensible way. Consider the output produced by the default\r
-formatting.\r
+The functions \code{xalign}, \code{xdigits}, and \code{xdisplay} are\r
+useful for formatting tables in a sensible way. Consider the output\r
+produced by the default formatting.\r
 \r
 <<results='asis'>>=\r
+data(mtcars)\r
 dat <- mtcars[1:3, 1:6]\r
 x <- xtable(dat)\r
 x\r
@@ -192,19 +306,19 @@ If you prefer $5 \times 10^5$ in your tables to 5e5, the
 \code{math.style.exponents} option to \code{print.xtable} is useful:\r
 \r
 <<results='asis'>>=\r
-print(xtable(data.frame(text=c("foo","bar"),\r
-                        googols=c(10e10,50e10),\r
-                        small=c(8e-24,7e-5),\r
-                        row.names=c("A","B")),\r
-             display=c("s","s","g","g")),\r
-      math.style.exponents=TRUE\r
-      )\r
-@ \r
+print(xtable(data.frame(text = c("foo","bar"),\r
+                        googols = c(10e10,50e10),\r
+                        small = c(8e-24,7e-5),\r
+                        row.names = c("A","B")),\r
+             display = c("s","s","g","g")),\r
+      math.style.exponents = TRUE)\r
+@\r
 \r
 this option also supports the values \code{ensuremath} which uses\r
 \code{\char`\\ensuremath} instead of \code{\$\$} and \code{UTF-8}\r
 which uses UTF-8 to approximate the \LaTeX typesetting.\r
 \r
+\r
 \section{Sanitization}\r
 <<results='asis'>>=\r
 insane <- data.frame(Name = c("Ampersand","Greater than","Less than",\r
@@ -220,6 +334,7 @@ xtable(insane)
 \p\r
 Sometimes you might want to have your own sanitization function.\r
 \r
+\r
 <<results='asis'>>=\r
 wanttex <- xtable(data.frame(Column =\r
                              paste("Value_is $10^{-",1:3,"}$", sep = "")))\r
@@ -227,11 +342,33 @@ print(wanttex, sanitize.text.function =
       function(str) gsub("_", "\\_", str, fixed = TRUE))\r
 @\r
 \r
+\p\r
+Sanitization can be useful in formatting column headings and row names:\r
+\r
+<<sanitize3>>=\r
+dat <- mtcars[1:3, 1:6]\r
+large <- function(x){\r
+  paste0('{\\Large{\\bfseries ', x, '}}')\r
+}\r
+italic <- function(x){\r
+  paste0('{\\emph{ ', x, '}}')\r
+}\r
+@ %def\r
+\r
+<<sanitize4, results = 'asis'>>=\r
+print(xtable(dat),\r
+      sanitize.rownames.function = italic,\r
+      sanitize.colnames.function = large,\r
+      booktabs = TRUE)\r
+@ %def\r
+\r
+\r
+\r
 \newpage\r
 \r
 \subsection{Markup in tables}\r
-Markup can be included in tables, including in column and row names, by using\r
-a custom \code{sanitize.text.function}.\r
+Markup can be included in tables, including in column and row names,\r
+by using a custom \code{sanitize.text.function}.\r
 \r
 <<results='asis'>>=\r
 mat <- round(matrix(c(0.9, 0.89, 200, 0.045, 2.0), c(1, 5)), 4)\r
@@ -354,9 +491,9 @@ print(tli.table, include.colnames = FALSE, include.rownames = FALSE)
 \newpage\r
 \r
 \subsection{Rotate row/column names}\r
-The \code{rotate.rownames} and \code{rotate.colnames} arguments can be used to\r
-rotate the row and/or column names. This requires \verb|\usepackage{rotating}|\r
-in the \LaTeX\ preamble.\r
+The \code{rotate.rownames} and \code{rotate.colnames} arguments can be\r
+used to rotate the row and/or column names. This requires\r
+\verb|\usepackage{rotating}| in the \LaTeX\ preamble.\r
 \r
 <<results='asis'>>=\r
 print(tli.table, rotate.rownames = TRUE, rotate.colnames = TRUE)\r
@@ -374,16 +511,17 @@ print(xtable(anova(fm3)), hline.after = c(1))
 @\r
 \r
 \subsubsection{Line styles}\r
-Specifying \code{booktabs = TRUE} will generate three line types. By default,\r
-when no value is given for \code{hline.after}, a \verb|\toprule| will be drawn\r
-above the table, a \verb|\midrule| after the table headings and a\r
-\verb|\bottomrule| below the table. This requires \verb|\usepackage{booktabs}|\r
-in the \LaTeX\ preamble.\r
+Specifying \code{booktabs = TRUE} will generate three line types. By\r
+default, when no value is given for \code{hline.after}, a\r
+\verb|\toprule| will be drawn above the table, a \verb|\midrule| after\r
+the table headings and a \verb|\bottomrule| below the table. This\r
+requires \verb|\usepackage{booktabs}| in the \LaTeX\ preamble.\r
 \r
 \p\r
-The top and bottom rules are slightly thicker than the mid rule. The thickness\r
-of the lines can be set via the \LaTeX\ lengths \verb|\heavyrulewidth| and\r
-\verb|\lightrulewidth|.\r
+\r
+The top and bottom rules are slightly thicker than the mid rule. The\r
+thickness of the lines can be set via the \LaTeX\ lengths\r
+\verb|\heavyrulewidth| and \verb|\lightrulewidth|.\r
 \r
 <<results='asis'>>=\r
 tli.table <- xtable(tli[1:10, ])\r
@@ -391,6 +529,7 @@ print(tli.table, include.rownames = FALSE, booktabs = TRUE)
 @\r
 \r
 \p\r
+\r
 If \code{hline.after} includes \code{-1}, a \verb|\toprule| will be\r
 drawn above the table. If \code{hline.after} includes the number of\r
 rows in the table, a \verb|\bottomrule| will be drawn below the\r
@@ -425,39 +564,22 @@ x.big <- xtable(x, caption = "A \\code{longtable} spanning several pages")
 print(x.big, hline.after=c(-1, 0), tabular.environment = "longtable")\r
 @\r
 \r
-%% The column name alignment is off in the following example.\r
-%% It needs some revision before exposing it. - CR, 7/2/2012\r
-%\r
-%% Tried to fix this and got some of the way, but \hlines are wrong\r
-%% and first column is too wide. - DJS 4/10/2014\r
-%% \subsubsection{Long tables with the header on each page}\r
-%% The \code{add.to.row} argument can be used to display the header\r
-%% for a long table on each page, and to add a "continued" footer\r
-%% on all pages except the last page.\r
-\r
-%% \newcommand{\head}[1]{\centercell{\bfseries#1}}\r
-\r
-%% <<results='asis'>>=\r
-%% x <- matrix(rnorm(1000), ncol = 10)\r
-%% hdr <-  paste(paste("\\multicolumn{1}{c}{",1:9,"} & ", collapse = ""),\r
-%%               "\\multicolumn{1}{c}{10}\\\\")\r
-%% addtorow <- list()\r
-%% addtorow$pos <- list()\r
-%% addtorow$pos[[1]] <- c(0)\r
-%% addtorow$command <- c(paste(\r
-%%     hdr,\r
-%%     "  \\hline \n",\r
-%%     "  \\endhead \n",\r
-%%     "  \\hline \n",\r
-%%     "  {\\footnotesize Continued on next page} \n",\r
-%%     "  \\endfoot \n",\r
-%%     "  \\endlastfoot \n", sep = ""))\r
-%% x.big2 <- xtable(x, label = "tabbig2", align = "lrrrrrrrrrr",\r
-%%                  caption = "Example of longtable with the header on each page")\r
-%% print(x.big2, tabular.environment = "longtable",\r
-%%       include.rownames = FALSE, include.colnames = FALSE,\r
-%%       add.to.row = addtorow)\r
-%% @\r
+Extra features of the \pkg{longtable} \LaTeX{} package can typically\r
+be activated using \code{add.to.row}, as shown below.\r
+\r
+<<results='asis'>>=\r
+add.to.row <- list(pos = list(0), command = NULL)\r
+command <- paste0("\\hline\n\\endhead\n",\r
+                  "\\hline\n",\r
+                  "\\multicolumn{", dim(x)[2] + 1, "}{l}",\r
+                  "{\\footnotesize Continued on next page}\n",\r
+                  "\\endfoot\n",\r
+                  "\\endlastfoot\n")\r
+add.to.row$command <- command\r
+print(x.big, hline.after=c(-1), add.to.row = add.to.row,\r
+      tabular.environment = "longtable")\r
+@\r
+\r
 \r
 \newpage\r
 \r
@@ -539,8 +661,8 @@ column formats.
 These allow for very sophisticated cell formatting, namely\r
 left-aligned, centred, or right-aligned text, with recognition of line\r
 breaks for the first three new column types. If these lines are\r
-included along with \verb|\usepackage{array}|, then the following\r
-is possible.\r
+included along with \verb|\usepackage{array}|, then the following is\r
+possible.\r
 \r
 \newcolumntype{L}[1]{>{\raggedright\let\newline\\\r
     \arraybackslash\hspace{0pt}}m{#1}}\r
@@ -560,10 +682,10 @@ print(xtable(df, align = c("l", "|c", "|R{3cm}", "|L{3cm}", "| p{3cm}|")),
 \newpage\r
 \r
 \subsection{Table width}\r
-The \code{tabularx} environment is for typesetting tables whose overall width is\r
-fixed. The column alignment code \code{X} denotes columns that will be stretched\r
-to achieve the desired table width. Requires \verb|\usepackage{tabularx}| in the\r
-\LaTeX\ preamble.\r
+The \code{tabularx} environment is for typesetting tables whose\r
+overall width is fixed. The column alignment code \code{X} denotes\r
+columns that will be stretched to achieve the desired table\r
+width. Requires \verb|\usepackage{tabularx}| in the \LaTeX\ preamble.\r
 \r
 <<results='asis'>>=\r
 df.width <- data.frame(One = c("item 1", "A"), Two = c("item 2", "B"),\r
@@ -574,9 +696,10 @@ print(x.width, tabular.environment = "tabularx", width = "\\textwidth")
 @\r
 \r
 \section{Suppressing printing}\r
-By default the \code{print} method will print the \LaTeX\ or HTML to standard\r
-output and also return the character strings invisibly.  The printing to\r
-standard output can be suppressed by specifying \code{print.results = FALSE}.\r
+By default the \code{print} method will print the \LaTeX\ or HTML to\r
+standard output and also return the character strings invisibly.  The\r
+printing to standard output can be suppressed by specifying\r
+\code{print.results = FALSE}.\r
 \r
 <<>>=\r
 x.out <- print(tli.table, print.results = FALSE)\r
@@ -592,6 +715,7 @@ class(x.ltx)
 x.ltx\r
 @\r
 \r
+\r
 \newpage\r
 \r
 \section{Acknowledgements}\r