[r-cran-xtable] 02/06: Imported Upstream version 1.7-4

Jonathon Love jon at thon.cc
Fri Apr 22 01:07:52 UTC 2016


This is an automated email from the git hooks/post-receive script.

jonathon-guest pushed a commit to branch master
in repository r-cran-xtable.

commit 54bb60a8d0c32584cf15a651f6174267aff41e15
Author: Jonathon Love <jon at thon.cc>
Date:   Fri Apr 22 10:36:06 2016 +1000

    Imported Upstream version 1.7-4
---
 DESCRIPTION                    |  14 +
 MD5                            |  26 ++
 NAMESPACE                      |  42 +++
 NEWS                           |  85 +++++
 R/print.xtable.R               | 704 +++++++++++++++++++++++++++++++++++++++++
 R/table.attributes.R           | 154 +++++++++
 R/toLatex.R                    |  40 +++
 R/xtable.R                     | 284 +++++++++++++++++
 build/vignette.rds             | Bin 0 -> 251 bytes
 data/tli.txt.gz                | Bin 0 -> 585 bytes
 inst/doc/margintable.R         |  18 ++
 inst/doc/margintable.Rnw       |  64 ++++
 inst/doc/margintable.pdf       | Bin 0 -> 90568 bytes
 inst/doc/xtableGallery.R       | 583 ++++++++++++++++++++++++++++++++++
 inst/doc/xtableGallery.pdf     | Bin 0 -> 239535 bytes
 inst/doc/xtableGallery.snw     | 585 ++++++++++++++++++++++++++++++++++
 man/print.xtable.Rd            | 242 ++++++++++++++
 man/string.Rd                  |  30 ++
 man/table.attributes.Rd        |  47 +++
 man/tli.Rd                     |  20 ++
 man/toLatex.Rd                 |  26 ++
 man/xtable.Rd                  | 384 ++++++++++++++++++++++
 tests/test.margintable.R       |  47 +++
 tests/test.xtable.R            |  27 ++
 tests/test.xtable.data.frame.R |  23 ++
 vignettes/margintable.Rnw      |  64 ++++
 vignettes/xtableGallery.snw    | 585 ++++++++++++++++++++++++++++++++++
 27 files changed, 4094 insertions(+)

diff --git a/DESCRIPTION b/DESCRIPTION
new file mode 100644
index 0000000..cdbb082
--- /dev/null
+++ b/DESCRIPTION
@@ -0,0 +1,14 @@
+Package: xtable
+Version: 1.7-4
+Date: 2014/08/17
+Title: Export tables to LaTeX or HTML
+Author: David B. Dahl <dahl at stat.byu.edu>
+Maintainer: David Scott <d.scott at auckland.ac.nz>
+Description: Coerce data to LaTeX and HTML tables
+URL: http://xtable.r-forge.r-project.org/
+Depends: R (>= 2.10.0)
+License: GPL (>= 2)
+Repository: CRAN
+Packaged: 2014-09-11 22:38:16 UTC; dsco036
+NeedsCompilation: no
+Date/Publication: 2014-09-12 14:30:04
diff --git a/MD5 b/MD5
new file mode 100644
index 0000000..859a8dd
--- /dev/null
+++ b/MD5
@@ -0,0 +1,26 @@
+2cb6fb8b229794a1f0b3f1942eda6442 *DESCRIPTION
+3b1d8bb64a284192c3090723f3973fe8 *NAMESPACE
+3cd1c6c94ca3385008051885faa0fae2 *NEWS
+2925af763dc97f52e15cec58c3a37865 *R/print.xtable.R
+224ad31199a69cbacb40593bc53670da *R/table.attributes.R
+a05e7179a5e51b4c0492dd92abd99cb5 *R/toLatex.R
+063aca83ae13f85e93b597e932423cac *R/xtable.R
+e461015597c171b358138351ac872a08 *build/vignette.rds
+b9a39bb9d8c88fbe0d3540a6ce1b11d3 *data/tli.txt.gz
+731fb95353666b59838b344a131a0c82 *inst/doc/margintable.R
+97de7ed6dfb487dc4888355c2355b137 *inst/doc/margintable.Rnw
+8f7529ffff1d2042e9d49727643d2bf4 *inst/doc/margintable.pdf
+88743ea9b7c8694fffd72bc5eb88892b *inst/doc/xtableGallery.R
+51086d16b8daed4035b9ee812f65471a *inst/doc/xtableGallery.pdf
+844a22a4adf2b2eddfd81757ed45b552 *inst/doc/xtableGallery.snw
+00c711d7e99853aab72f0c14bfb2c527 *man/print.xtable.Rd
+be0c2da0f5526de7a7bbaf045476255b *man/string.Rd
+3558d3ec1913057bed0f7e50cb5f10ff *man/table.attributes.Rd
+3c6841334d41dd4be535503ed29abd27 *man/tli.Rd
+495dd6344cfa0335bb8018c094e081b3 *man/toLatex.Rd
+f643d895edf3b6d2bdba5111486b0f53 *man/xtable.Rd
+596b4f4f3c425330eb54998231aca58b *tests/test.margintable.R
+12b35182cb70b6f47d262213b7e1b342 *tests/test.xtable.R
+3089b65c174191d5245050a760a86746 *tests/test.xtable.data.frame.R
+97de7ed6dfb487dc4888355c2355b137 *vignettes/margintable.Rnw
+844a22a4adf2b2eddfd81757ed45b552 *vignettes/xtableGallery.snw
diff --git a/NAMESPACE b/NAMESPACE
new file mode 100644
index 0000000..52dbdd6
--- /dev/null
+++ b/NAMESPACE
@@ -0,0 +1,42 @@
+# NAMESPACE work by Robert Gentleman <rgentlem at fhcrc.org>
+# in e-mail on July 30, 2007.
+#
+# Extended by C Roosen, 30/01/2012
+
+importFrom("utils", toLatex)
+
+export("caption<-", "caption", "label", "label<-",
+   "align<-", "align", "digits<-", "digits", "display<-",
+   "display", "xtable", "print.xtable", "toLatex.xtable")
+
+S3method("print", "xtable")
+S3method("toLatex", "xtable")
+
+S3method("caption<-", "xtable")
+S3method("caption", "xtable")
+S3method("label", "xtable")
+S3method("label<-", "xtable")
+S3method("align<-", "xtable")
+S3method("align", "xtable")
+S3method("digits", "xtable")
+S3method("digits<-", "xtable")
+S3method("display<-", "xtable")
+S3method("display", "xtable")
+
+S3method("xtable", "data.frame")
+S3method("xtable", "matrix")
+S3method("xtable", "table")
+S3method("xtable", "anova")
+S3method("xtable", "aov")
+S3method("xtable", "summary.aov")
+S3method("xtable", "summary.aovlist")
+S3method("xtable", "aovlist")
+S3method("xtable", "lm")
+S3method("xtable", "summary.lm")
+S3method("xtable", "glm")
+S3method("xtable", "summary.glm")
+S3method("xtable", "prcomp")
+S3method("xtable", "summary.prcomp")
+S3method("xtable", "coxph")
+S3method("xtable", "ts")
+S3method("xtable", "zoo")
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..30250af
--- /dev/null
+++ b/NEWS
@@ -0,0 +1,85 @@
+
+1.7-4 (NOT YET RELEASED)
+  * Changed tags in HTML to be all lower case, to be compatible with
+    HTML5, part of feature request(#5879)
+  * Fixed booktabs bug (#2309), more of an enhancement really. Updated
+    xtableGallery.snw to illustrate the change.
+  * Moved vignettes from inst/doc to vignettes as now required by CRAN
+  * Changed email address of David Dahl to dahl at stat.byu.edu in 9 places
+
+1.7-3 (2014-03-06)
+  * Released to CRAN
+
+1.7-2 (2013-08-28, Not Released to CRAN)
+  * Fixed HTML gsub bug (#2795)
+  * Dealt with format.args bug (#4770). No code changes, but the
+    documentation of print.xtable was changed to warn of the problem
+    and to give a workaround as an example
+
+1.7-1 (2013-02-24)
+  * Fixed logicals bug (Req #1911)
+  * Changed implementation of centering of tables. Instead of
+    inserting a centered environment, now a \centering command is
+    inserted. (Req #2104)
+  * Allow for margin tables as possible with document class
+    tufte-handout. An example of usage is found in the vignette
+	produced by margintable.Rnw which is in inst/doc. (Req #2168)
+  * Added "timestamp" argument to print.xtable().  Set it to NULL
+    if no timestamp is desired. (Req #2246)
+  * Added "comment" argument to print.xtable().  Set it to FALSE
+    to exclude the version and timestamp comment. (Req #2246)
+  * Added "caption.width" argument.  If not NULL then the caption
+    is placed in a "parbox" of the specified width. (Req #2247)
+  * Remove the check on whether the "floating.environment" is in a
+    list of known floating environments. Users want to use floating
+    environments from multiple options LaTeX packages (Req #2488,
+    #2578)
+
+1.7-0 (2012-02-10)
+  * Added some vectorization code to improve performance.
+  * Let "caption" be length 2, in which case the second value is
+    the short caption used when creating a list of tables.
+  * Added "toLatex" method.
+  * Included "print.xtable" in the exported methods in the NAMESPACE file.
+  * Added "print.results" argument to "print" that can be used to
+    suppress the printing.
+  * Added "format.args" argument to "print" that can be used to
+    pass additional arguments such as "big.marks" to "formatC()".
+  * Added "rotate.colnames" and "rotate.rownames" arguments to
+    "print.xtable".
+  * Added "booktabs" argument to use the "\toprule", "\midrule", and
+    "\bottomrule" tags from the Latex "booktabs" package rather than
+	using "\hline" for all horizontal lines.
+  * Added "scalebox" argument to include a "\scalebox" clause around
+    the tabular environment with the specified value used as the
+    scaling factor.
+  * Added "width" argument to allow specification of the width
+    value in tabular environments such as "tabularx".
+  * Added "X" as an allowed alignment value in the "align()"
+    replacement function.
+  * Changed the "print.xtable()" arguments to use "getOption()"
+    to check the options for a default value.  This was suggested
+	since "print.xtable()" has a lot of arguments that the user
+	will typically leave unchanged between tables.
+  * Added an "is.null()" check on the "table.placement" argument.
+  * Added examples using the new arguments to the vignette.
+
+1.6-0 (2011-10-07)
+  * Allow "table*" as a value for "floating.environment" in print.xtable().
+  * Fix bug under which multiple logical columns were formatted incorrectly.
+  * Stop with an error if "xtable.table" is used on a table with more than
+    two dimensions.
+  * Add some newlines to "Rd" file to prevent lines from extending off the
+    page in the PDF version of the help files.
+  * Changed the maintainer to "Charles Roosen".
+  * Created an "xtable" project on R-Forge.
+
+1.5-6 (2009-10-30)
+  * Support caption at the top in the LaTeX longtable.
+  * Use options()$OutDec for decimal mark.
+
+1.5-5 (2009-03-24)
+  * Added html.table.attributes to set the attributed of the <TABLE> tag for HTML tables.
+  * Accommodated logicals by converting to characters.
+  * Add an extra space at end of each line for LaTeX tables.
+  * Fixed typographical error in documentation.
diff --git a/R/print.xtable.R b/R/print.xtable.R
new file mode 100644
index 0000000..67f48d5
--- /dev/null
+++ b/R/print.xtable.R
@@ -0,0 +1,704 @@
+### xtable package
+###
+### Produce LaTeX and HTML tables from R objects.
+###
+### Copyright 2000-2013 David B. Dahl <dahl at stat.byu.edu>
+###
+### Maintained by David Scott <d.scott at auckland.ac.nz>
+###
+### This file is part of the `xtable' library for R and related languages.
+### It is made available under the terms of the GNU General Public
+### License, version 2, or at your option, any later version,
+### incorporated herein by reference.
+###
+### This program is distributed in the hope that it will be
+### useful, but WITHOUT ANY WARRANTY; without even the implied
+### warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+### PURPOSE.  See the GNU General Public License for more
+### details.
+###
+### You should have received a copy of the GNU General Public
+### License along with this program; if not, write to the Free
+### Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+### MA 02111-1307, USA
+print.xtable <- 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", c(-1,0,nrow(x))),
+  NA.string = getOption("xtable.NA.string", ""),
+  include.rownames = getOption("xtable.include.rownames", TRUE),
+  include.colnames = getOption("xtable.include.colnames", TRUE),
+  only.contents = getOption("xtable.only.contents", FALSE),
+  add.to.row = getOption("xtable.add.to.row", NULL),
+  sanitize.text.function = getOption("xtable.sanitize.text.function", NULL),
+  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),
+  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 caption is length 2, treat the second value as the "short caption"
+    caption <- attr(x,"caption",exact = TRUE)
+    short.caption <- NULL
+    if (!is.null(caption) && length(caption) > 1){
+        short.caption <- caption[2]
+	caption <- caption[1]
+    }
+
+    ## Claudio Agostinelli <claudio at unive.it> dated 2006-07-28 hline.after
+    ## By default it print an \hline before and after the columns names
+    ## independently they are printed or not and at the end of the table
+    ## Old code that set hline.after should include c(-1, 0, nrow(x)) in the
+    ## hline.after vector
+    ## If you do not want any \hline inside the data, set hline.after to NULL
+    ## PHEADER instead the string '\\hline\n' is used in the code
+    ## Now hline.after counts how many time a position appear
+    ## I left an automatic PHEADER in the longtable is this correct?
+
+    ## Claudio Agostinelli <claudio at unive.it> dated 2006-07-28 include.rownames,
+    ## include.colnames
+    pos <- 0
+    if (include.rownames) pos <- 1
+
+    ## Claudio Agostinelli <claudio at unive.it> dated 2006-07-28
+    ## hline.after checks
+    if (any(hline.after < -1) | any(hline.after > nrow(x))) {
+        stop("'hline.after' must be inside [-1, nrow(x)]")
+    }
+
+    ## Claudio Agostinelli <claudio at unive.it> dated 2006-07-28
+    ## add.to.row checks
+    if (!is.null(add.to.row)) {
+        if (is.list(add.to.row) && length(add.to.row) == 2) {
+            if (is.null(names(add.to.row))) {
+                names(add.to.row) <- c('pos', 'command')
+            } else if (any(sort(names(add.to.row))!= c('command', 'pos'))) {
+                stop("the names of the elements of 'add.to.row' must be 'pos' and 'command'")
+            }
+            if (is.list(add.to.row$pos) && is.vector(add.to.row$command,
+                                                     mode = 'character')) {
+                if ((npos <- length(add.to.row$pos)) !=
+                    length(add.to.row$command)) {
+                    stop("the length of 'add.to.row$pos' must be equal to the length of 'add.to.row$command'")
+                }
+                if (any(unlist(add.to.row$pos) < -1) |
+                    any(unlist(add.to.row$pos) > nrow(x))) {
+                    stop("the values in add.to.row$pos must be inside the interval [-1, nrow(x)]")
+                }
+            } else {
+                stop("the first argument ('pos') of 'add.to.row' must be a list, the second argument ('command') must be a vector of mode character")
+            }
+        } else {
+            stop("'add.to.row' argument must be a list of length 2")
+        }
+    } else {
+        add.to.row <- list(pos = list(),
+                           command = vector(length = 0, mode = "character"))
+        npos <- 0
+    }
+
+    ## Claudio Agostinelli <claudio at unive.it> dated 2006-07-28 add.to.row
+    ## Add further commands at the end of rows
+    if (type == "latex") {
+        ## Original code before changes in version 1.6-1
+        ## PHEADER <- "\\hline\n"
+
+        ## booktabs code from Matthieu Stigler <matthieu.stigler at gmail.com>,
+        ## 1 Feb 2012
+        if(!booktabs){
+            PHEADER <- "\\hline\n"
+        } else {
+            ## This code replaced to fix bug #2309, David Scott, 8 Jan 2014
+            ## PHEADER <- ifelse(-1%in%hline.after, "\\toprule\n", "")
+            ## if(0%in%hline.after) {
+            ##     PHEADER <- c(PHEADER, "\\midrule\n")
+            ## }
+            ## if(nrow(x)%in%hline.after) {
+            ##     PHEADER <- c(PHEADER, "\\bottomrule\n")
+            ## }
+            if (is.null(hline.after)){
+                PHEADER <- ""
+            } else {
+                hline.after <- sort(hline.after)
+                PHEADER <- rep("\\midrule\n", length(hline.after))
+                if (hline.after[1] == -1) {
+                    PHEADER[1] <- "\\toprule\n"
+                }
+                if (hline.after[length(hline.after)] == nrow(x)) {
+                    PHEADER[length(hline.after)] <- "\\bottomrule\n"
+                }
+            }
+        }
+    } else {
+        PHEADER <- ""
+    }
+
+        lastcol <- rep(" ", nrow(x)+2)
+    if (!is.null(hline.after)) {
+        ## booktabs change - Matthieu Stigler: fill the hline arguments
+        ## separately, 1 Feb 2012
+        ##
+        ## Code before booktabs change was:
+        ##    add.to.row$pos[[npos+1]] <- hline.after
+
+        if (!booktabs){
+            add.to.row$pos[[npos+1]] <- hline.after
+	    } else {
+            for(i in 1:length(hline.after)) {
+                add.to.row$pos[[npos+i]] <- hline.after[i]
+            }
+        }
+        add.to.row$command <- c(add.to.row$command, PHEADER)
+    }
+
+    if ( length(add.to.row$command) > 0 ) {
+        for (i in 1:length(add.to.row$command)) {
+            addpos <- add.to.row$pos[[i]]
+            freq <- table(addpos)
+            addpos <- unique(addpos)
+            for (j in 1:length(addpos)) {
+                lastcol[addpos[j]+2] <- paste(lastcol[addpos[j]+2],
+                                              paste(rep(add.to.row$command[i],
+                                                        freq[j]),
+                                                sep = "", collapse = ""),
+                                              sep = " ")
+            }
+        }
+    }
+
+    if (length(type)>1) stop("\"type\" must have length 1")
+    type <- tolower(type)
+    if (!all(!is.na(match(type, c("latex","html"))))) {
+        stop("\"type\" must be in {\"latex\", \"html\"}")
+    }
+    ## Disabling the check on known floating environments as many users
+    ## want to use additional environments.
+    #    if (!all(!is.na(match(floating.environment,
+    #                          c("table","table*","sidewaystable",
+    #                            "margintable"))))) {
+    #        stop("\"type\" must be in {\"table\", \"table*\", \"sidewaystable\", \"margintable\"}")
+    #    }
+    if (("margintable" %in% floating.environment)
+        & (!is.null(table.placement))) {
+        warning("margintable does not allow for table placement; setting table.placement to NULL")
+        table.placement <- NULL
+    }
+    if (!is.null(table.placement) &&
+        !all(!is.na(match(unlist(strsplit(table.placement,  split = "")),
+                          c("H","h","t","b","p","!"))))) {
+        stop("\"table.placement\" must contain only elements of {\"h\",\"t\",\"b\",\"p\",\"!\"}")
+    }
+    if (!all(!is.na(match(caption.placement, c("bottom","top"))))) {
+        stop("\"caption.placement\" must be either {\"bottom\",\"top\"}")
+    }
+
+    if (type == "latex") {
+        BCOMMENT <- "% "
+        ECOMMENT <- "\n"
+        ## See e-mail from "John S. Walker <jsw9c at uic.edu>" dated 5-19-2003
+        ## regarding "texfloat"
+        ## See e-mail form "Fernando Henrique Ferraz P. da Rosa"
+        ## <academic at feferraz.net>" dated 10-28-2005 regarding "longtable"
+        if ( tabular.environment == "longtable" & floating == TRUE ) {
+            warning("Attempt to use \"longtable\" with floating = TRUE. Changing to FALSE.")
+            floating <- FALSE
+        }
+        if ( floating == TRUE ) {
+            ## See e-mail from "Pfaff, Bernhard <Bernhard.Pfaff at drkw.com>"
+            ## dated 7-09-2003 regarding "suggestion for an amendment of
+            ## the source"
+            ## See e-mail from "Mitchell, David"
+            ## <David.Mitchell at dotars.gov.au>" dated 2003-07-09 regarding
+            ## "Additions to R xtable package"
+            ## See e-mail from "Garbade, Sven"
+            ## <Sven.Garbade at med.uni-heidelberg.de> dated 2006-05-22
+            ## regarding the floating environment.
+            BTABLE <- paste("\\begin{", floating.environment, "}",
+                            ifelse(!is.null(table.placement),
+                                   paste("[", table.placement, "]", sep = ""),
+                                   ""), "\n", sep = "")
+            if ( is.null(latex.environments) ||
+                (length(latex.environments) == 0) ) {
+                BENVIRONMENT <- ""
+                EENVIRONMENT <- ""
+            } else {
+                BENVIRONMENT <- ""
+                EENVIRONMENT <- ""
+                if ("center" %in% latex.environments){
+                    BENVIRONMENT <- paste(BENVIRONMENT, "\\centering\n",
+                                          sep = "")
+                }
+                for (i in 1:length(latex.environments)) {
+                    if (latex.environments[i] == "") next
+                    if (latex.environments[i] != "center"){
+                        BENVIRONMENT <- paste(BENVIRONMENT,
+                                              "\\begin{", latex.environments[i],
+                                              "}\n", sep = "")
+                        EENVIRONMENT <- paste("\\end{", latex.environments[i],
+                                              "}\n", EENVIRONMENT, sep = "")
+                    }
+                }
+            }
+            ETABLE <- paste("\\end{", floating.environment, "}\n", sep = "")
+        } else {
+            BTABLE <- ""
+            ETABLE <- ""
+            BENVIRONMENT <- ""
+            EENVIRONMENT <- ""
+        }
+
+        tmp.index.start <- 1
+        if ( ! include.rownames ) {
+            while ( attr(x, "align", exact = TRUE)[tmp.index.start] == '|' )
+                tmp.index.start <- tmp.index.start + 1
+            tmp.index.start <- tmp.index.start + 1
+        }
+        ## Added "width" argument for use with "tabular*" or
+        ## "tabularx" environments - CR, 7/2/12
+        if (is.null(width)){
+            WIDTH <-""
+        } else if (is.element(tabular.environment,
+                              c("tabular", "longtable"))){
+            warning("Ignoring 'width' argument.  The 'tabular' and 'longtable' environments do not support a width specification.  Use another environment such as 'tabular*' or 'tabularx' to specify the width.")
+            WIDTH <- ""
+        } else {
+            WIDTH <- paste("{", width, "}", sep = "")
+        }
+
+        BTABULAR <-
+            paste("\\begin{", tabular.environment, "}",
+                  WIDTH, "{",
+                  paste(c(attr(x, "align",
+                               exact = TRUE)[
+                               tmp.index.start:length(attr(x, "align",
+                                                           exact = TRUE))],
+                          "}\n"),
+                        sep = "", collapse = ""),
+                  sep = "")
+
+        ## fix 10-26-09 (robert.castelo at upf.edu) the following
+        ## 'if' condition is added here to support
+        ## a caption on the top of a longtable
+        if (tabular.environment == "longtable" && caption.placement == "top") {
+            if (is.null(short.caption)){
+                BCAPTION <- "\\caption{"
+            } else {
+                BCAPTION <- paste("\\caption[", short.caption, "]{", sep = "")
+            }
+            ECAPTION <- "} \\\\ \n"
+            if ((!is.null(caption)) && (type == "latex")) {
+                BTABULAR <- paste(BTABULAR,  BCAPTION, caption, ECAPTION,
+                                  sep = "")
+            }
+        }
+        ## Claudio Agostinelli <claudio at unive.it> dated 2006-07-28
+        ## add.to.row position -1
+        BTABULAR <- paste(BTABULAR, lastcol[1], sep = "")
+        ## the \hline at the end, if present, is set in full matrix
+        ETABULAR <- paste("\\end{", tabular.environment, "}\n", sep = "")
+
+        ## Add scalebox - CR, 7/2/12
+        if (!is.null(scalebox)){
+            BTABULAR <- paste("\\scalebox{", scalebox, "}{\n", BTABULAR,
+                              sep = "")
+            ETABULAR <- paste(ETABULAR, "}\n", sep = "")
+        }
+
+        ## BSIZE contributed by Benno <puetz at mpipsykl.mpg.de> in e-mail
+        ## dated Wednesday, December 01, 2004
+        if (is.null(size) || !is.character(size)) {
+            BSIZE <- ""
+            ESIZE <- ""
+        } else {
+            if(length(grep("^\\\\", size)) == 0){
+                size <- paste("\\", size, sep = "")
+            }
+            BSIZE <- paste("{", size, "\n", sep = "")
+            ESIZE <- "}\n"
+        }
+        BLABEL <- "\\label{"
+        ELABEL <- "}\n"
+        ## Added caption width (jeff.laake at nooa.gov)
+	    if(!is.null(caption.width)){
+	        BCAPTION <- paste("\\parbox{",caption.width,"}{",sep="")
+	        ECAPTION <- "}"
+	    } else {
+	        BCAPTION <- NULL
+	        ECAPTION <- NULL
+	    }
+	    if (is.null(short.caption)){
+		   BCAPTION <- paste(BCAPTION,"\\caption{",sep="")
+	    } else {
+		   BCAPTION <- paste(BCAPTION,"\\caption[", short.caption, "]{", sep="")
+	    }
+        ECAPTION <- paste(ECAPTION,"} \n",sep="")
+        BROW <- ""
+        EROW <- " \\\\ \n"
+        BTH <- ""
+        ETH <- ""
+        STH <- " & "
+        BTD1 <- " & "
+        BTD2 <- ""
+        BTD3 <- ""
+        ETD  <- ""
+        ## Based on contribution from Jonathan Swinton
+        ## <jonathan at swintons.net> in e-mail dated Wednesday, January 17, 2007
+        sanitize <- function(str) {
+            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)
+        }
+        sanitize.numbers <- function(x) {
+            result <- x
+            if ( math.style.negative ) {
+                ## Jake Bowers <jwbowers at illinois.edu> in e-mail
+                ## from 2008-08-20 suggested disabling this feature to avoid
+                ## problems with LaTeX's dcolumn package.
+                ## by Florian Wickelmaier <florian.wickelmaier at uni-tuebingen.de>
+                ## in e-mail from 2008-10-03 requested the ability to use the
+                ## old behavior.
+                for(i in 1:length(x)) {
+                    result[i] <- gsub("-", "$-$", result[i], fixed = TRUE)
+                }
+            }
+            return(result)
+        }
+        sanitize.final <- function(result) {
+            return(result)
+        }
+    } else {
+        BCOMMENT <- "<!-- "
+        ECOMMENT <- " -->\n"
+        BTABLE <- paste("<table ", html.table.attributes, ">\n", sep = "")
+        ETABLE <- "</table>\n"
+        BENVIRONMENT <- ""
+        EENVIRONMENT <- ""
+        BTABULAR <- ""
+        ETABULAR <- ""
+        BSIZE <- ""
+        ESIZE <- ""
+        BLABEL <- "<a name="
+        ELABEL <- "></a>\n"
+        BCAPTION <- paste("<caption align=\"", caption.placement, "\"> ",
+                          sep = "")
+        ECAPTION <- " </caption>\n"
+        BROW <- "<tr>"
+        EROW <- " </tr>\n"
+        BTH <- " <th> "
+        ETH <- " </th> "
+        STH <- " </th> <th> "
+        BTD1 <- " <td align=\""
+        align.tmp <- attr(x, "align", exact = TRUE)
+        align.tmp <- align.tmp[align.tmp!="|"]
+        BTD2 <- matrix(align.tmp[(2-pos):(ncol(x)+1)],
+                       nrow = nrow(x), ncol = ncol(x)+pos, byrow = TRUE)
+        ## Based on contribution from Jonathan Swinton <jonathan at swintons.net>
+        ## in e-mail dated Wednesday, January 17, 2007
+        BTD2[regexpr("^p", BTD2)>0] <- "left"
+        BTD2[BTD2 == "r"] <- "right"
+        BTD2[BTD2 == "l"] <- "left"
+        BTD2[BTD2 == "c"] <- "center"
+        BTD3 <- "\"> "
+        ETD  <- " </td>"
+        sanitize <- function(str) {
+            result <- str
+            ## Changed as suggested in bug report #2795
+            ## That is replacement of "&" is "&"
+            ## instead of previous "&amp" etc
+            ## result <- gsub("&", "&amp ", result, fixed = TRUE)
+            ## result <- gsub(">", "&gt ", result, fixed = TRUE)
+            ## result <- gsub("<", "&lt ", result, fixed = TRUE)
+            result <- gsub("&", "&", result, fixed = TRUE)
+            result <- gsub(">", ">", result, fixed = TRUE)
+            result <- gsub("<", "<", result, fixed = TRUE)
+            ## Kurt Hornik <Kurt.Hornik at wu-wien.ac.at> on 2006/10/05
+            ## recommended not escaping underscores.
+            ## result <- gsub("_", "\\_", result, fixed=TRUE)
+            return(result)
+        }
+        sanitize.numbers <- function(x) {
+            return(x)
+        }
+        sanitize.final <- function(result) {
+            ## Suggested by Uwe Ligges <ligges at statistik.uni-dortmund.de>
+            ## in e-mail dated 2005-07-30.
+            result$text <- gsub("  *", " ",  result$text, fixed = TRUE)
+            result$text <- gsub(' align="left"',  "", result$text,
+                                fixed = TRUE)
+            return(result)
+        }
+    }
+
+    result <- string("", file = file, append = append)
+    info <- R.Version()
+    ## modified Claudio Agostinelli <claudio at unive.it> dated 2006-07-28
+    ## to set automatically the package version
+	if (comment){
+        result <- result + BCOMMENT + type + " table generated in " +
+              info$language + " " + info$major + "." + info$minor +
+              " by xtable " +  packageDescription('xtable')$Version +
+              " package" + ECOMMENT
+        if (!is.null(timestamp)){
+            result <- result + BCOMMENT + timestamp + ECOMMENT
+        }
+    }
+    ## Claudio Agostinelli <claudio at unive.it> dated 2006-07-28 only.contents
+    if (!only.contents) {
+        result <- result + BTABLE
+        result <- result + BENVIRONMENT
+        if ( floating == TRUE ) {
+            if ((!is.null(caption)) &&
+                (type == "html" ||caption.placement == "top")) {
+                result <- result + BCAPTION + caption + ECAPTION
+            }
+            if (!is.null(attr(x, "label", exact = TRUE)) &&
+                (type == "latex" && caption.placement == "top")) {
+                result <- result + BLABEL +
+                          attr(x, "label", exact = TRUE) + ELABEL
+            }
+        }
+        result <- result + BSIZE
+        result <- result + BTABULAR
+    }
+    ## Claudio Agostinelli <claudio at unive.it> dated 2006-07-28
+    ## include.colnames, include.rownames
+    if (include.colnames) {
+        result <- result + BROW + BTH
+        if (include.rownames) {
+            result <- result + STH
+	}
+        ## David G. Whiting in e-mail 2007-10-09
+        if (is.null(sanitize.colnames.function)) {
+            CNAMES <- sanitize(names(x))
+	} else {
+            CNAMES <- sanitize.colnames.function(names(x))
+	}
+        if (rotate.colnames) {
+            ##added by Markus Loecher, 2009-11-16
+            CNAMES <- paste("\\begin{sideways}", CNAMES, "\\end{sideways}")
+	}
+        result <- result + paste(CNAMES, collapse = STH)
+
+        result <- result + ETH + EROW
+    }
+
+    cols <- matrix("", nrow = nrow(x), ncol = ncol(x)+pos)
+    if (include.rownames) {
+        ## David G. Whiting in e-mail 2007-10-09
+        if (is.null(sanitize.rownames.function)) {
+            RNAMES <- sanitize(row.names(x))
+        } else {
+            RNAMES <- sanitize.rownames.function(row.names(x))
+        }
+        if (rotate.rownames) {
+            ##added by Markus Loecher, 2009-11-16
+            RNAMES <- paste("\\begin{sideways}", RNAMES, "\\end{sideways}")
+	}
+	cols[, 1] <- RNAMES
+    }
+
+## Begin vectorizing the formatting code by Ian Fellows [ian at fellstat.com]
+## 06 Dec 2011
+##
+##  disp <- function(y) {
+##    if (is.factor(y)) {
+##      y <- levels(y)[y]
+##    }
+##    if (is.list(y)) {
+##      y <- unlist(y)
+##    }
+##    return(y)
+##  }
+    varying.digits <- is.matrix( attr( x, "digits", exact = TRUE ) )
+    ## Code for letting "digits" be a matrix was provided by
+    ## Arne Henningsen <ahenningsen at agric-econ.uni-kiel.de>
+    ## in e-mail dated 2005-06-04.
+    ##if( !varying.digits ) {
+    ## modified Claudio Agostinelli <claudio at unive.it> dated 2006-07-28
+    ##  attr(x,"digits") <- matrix( attr( x, "digits",exact=TRUE ),
+    ## nrow = nrow(x), ncol = ncol(x)+1, byrow = TRUE )
+    ##}
+    for(i in 1:ncol(x)) {
+ 	xcol <- x[, i]
+	if(is.factor(xcol))
+            xcol <- as.character(xcol)
+	if(is.list(xcol))
+            xcol <- sapply(xcol, unlist)
+        ina <- is.na(xcol)
+        is.numeric.column <- is.numeric(xcol)
+
+	if(is.character(xcol)) {
+            cols[, i+pos] <- xcol
+	} else {
+            if (is.null(format.args)){
+                format.args <- list()
+            }
+            if (is.null(format.args$decimal.mark)){
+                format.args$decimal.mark <- options()$OutDec
+            }
+            if(!varying.digits){
+		curFormatArgs <-
+                    c(list(
+                      x = xcol,
+                      format =
+                      ifelse(attr(x, "digits", exact = TRUE )[i+1] < 0, "E",
+                                   attr(x, "display", exact = TRUE )[i+1]),
+                      digits = abs(attr(x, "digits", exact = TRUE )[i+1])),
+                      format.args)
+                cols[, i+pos] <- do.call("formatC", curFormatArgs)
+            }else{
+		for( j in 1:nrow( cols ) ) {
+                    curFormatArgs <-
+                        c(list(
+                          x = xcol[j],
+                          format =
+                          ifelse(attr(x, "digits", exact = TRUE )[j, i+1] < 0,
+                                 "E", attr(x, "display", exact = TRUE )[i+1]),
+                          digits =
+                          abs(attr(x, "digits", exact = TRUE )[j, i+1])),
+                          format.args)
+                    cols[j, i+pos] <- do.call("formatC", curFormatArgs)
+		}
+            }
+	}
+	## End Ian Fellows changes
+
+        if ( any(ina) ) cols[ina, i+pos] <- NA.string
+        ## Based on contribution from Jonathan Swinton <jonathan at swintons.net>
+        ## in e-mail dated Wednesday, January 17, 2007
+        if ( is.numeric.column ) {
+            cols[, i+pos] <- sanitize.numbers(cols[, i+pos])
+        } else {
+            if (is.null(sanitize.text.function)) {
+                cols[, i+pos] <- sanitize(cols[, i+pos])
+            } else {
+                cols[, i+pos] <- sanitize.text.function(cols[, i+pos])
+            }
+        }
+    }
+
+    multiplier <- 5
+    full <- matrix("", nrow = nrow(x), ncol = multiplier*(ncol(x)+pos)+2)
+    full[, 1] <- BROW
+    full[, multiplier*(0:(ncol(x)+pos-1))+2] <- BTD1
+    full[, multiplier*(0:(ncol(x)+pos-1))+3] <- BTD2
+    full[, multiplier*(0:(ncol(x)+pos-1))+4] <- BTD3
+    full[, multiplier*(0:(ncol(x)+pos-1))+5] <- cols
+    full[, multiplier*(0:(ncol(x)+pos-1))+6] <- ETD
+
+    full[, multiplier*(ncol(x)+pos)+2] <- paste(EROW, lastcol[-(1:2)],
+                                                sep = " ")
+
+    if (type == "latex") full[, 2] <- ""
+    result <- result + lastcol[2] + paste(t(full), collapse = "")
+    if (!only.contents) {
+        if (tabular.environment == "longtable") {
+            ## booktabs change added the if() - 1 Feb 2012
+            if(!booktabs) {
+                result <- result + PHEADER
+            }
+
+            ## fix 10-27-09 Liviu Andronic (landronimirc at gmail.com) the
+            ## following 'if' condition is inserted in order to avoid
+            ## that bottom caption interferes with a top caption of a longtable
+            if(caption.placement == "bottom"){
+                if ((!is.null(caption)) && (type == "latex")) {
+                    result <- result + BCAPTION + caption + ECAPTION
+                }
+            }
+            if (!is.null(attr(x, "label", exact = TRUE))) {
+                result <- result + BLABEL + attr(x, "label", exact = TRUE) +
+                    ELABEL
+            }
+            ETABULAR <- "\\end{longtable}\n"
+        }
+        result <- result + ETABULAR
+        result <- result + ESIZE
+        if ( floating == TRUE ) {
+            if ((!is.null(caption)) &&
+                (type == "latex" && caption.placement == "bottom")) {
+                result <- result + BCAPTION + caption + ECAPTION
+            }
+            if (!is.null(attr(x, "label", exact = TRUE)) &&
+                caption.placement == "bottom") {
+                result <- result + BLABEL + attr(x, "label", exact = TRUE) +
+                    ELABEL
+            }
+        }
+        result <- result + EENVIRONMENT
+        result <- result + ETABLE
+    }
+    result <- sanitize.final(result)
+
+    if (print.results){
+	print(result)
+    }
+
+    return(invisible(result$text))
+}
+
+"+.string" <- function(x, y) {
+    x$text <- paste(x$text, as.string(y)$text, sep = "")
+    return(x)
+}
+
+print.string <- function(x, ...) {
+    cat(x$text, file = x$file, append = x$append)
+    return(invisible())
+}
+
+string <- function(text, file = "", append = FALSE) {
+    x <- list(text = text, file = file, append = append)
+    class(x) <- "string"
+    return(x)
+}
+
+as.string <- function(x, file = "", append = FALSE) {
+    if (is.null(attr(x, "class", exact = TRUE)))
+        switch(data.class(x),
+               character = return(string(x, file, append)),
+               numeric = return(string(as.character(x), file, append)),
+               stop("Cannot coerce argument to a string"))
+    if (class(x) == "string")
+        return(x)
+    stop("Cannot coerce argument to a string")
+}
+
+is.string <- function(x) {
+    return(class(x) == "string")
+}
+
diff --git a/R/table.attributes.R b/R/table.attributes.R
new file mode 100644
index 0000000..718e41f
--- /dev/null
+++ b/R/table.attributes.R
@@ -0,0 +1,154 @@
+### xtable package
+###
+### Produce LaTeX and HTML tables from R objects.
+###
+### Copyright 2000-2013 David B. Dahl <dahl at stat.byu.edu>
+###
+### This file is part of the `xtable' library for R and related languages.
+### It is made available under the terms of the GNU General Public
+### License, version 2, or at your option, any later version,
+### incorporated herein by reference.
+###
+### This program is distributed in the hope that it will be
+### useful, but WITHOUT ANY WARRANTY; without even the implied
+### warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+### PURPOSE.  See the GNU General Public License for more
+### details.
+###
+### You should have received a copy of the GNU General Public
+### License along with this program; if not, write to the Free
+### 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)
+    stop("\"caption\" must have length 1 or 2")
+  attr(x,"caption") <- value
+  return(x)
+}
+
+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)
+    stop("\"label\" must have length 1")
+  attr(x,"label") <- value
+  return(x)
+}
+
+label <- function(x,...) UseMethod("label")
+label.xtable <- function(x,...) {
+  return(attr(x,"label",exact=TRUE))
+}
+
+"align<-" <- function(x,value) UseMethod("align<-")
+
+# Based on contribution from Jonathan Swinton <jonathan at 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}"
+  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?
+    thisWidth <- ""
+    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))
+    } else {
+      wString <- substr(wString,2,nchar(wString))
+    }
+    aString.Width <- c(aString.Width,thisWidth)
+  }
+
+  alignAllowed <- c("l","r","p","c","|","X")
+
+  if (any( !(aString.Align %in% alignAllowed))) {
+    warning("Nonstandard alignments in align string")
+  }
+  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 at mpipsykl.mpg.de> in e-mail dated Wednesday, December 01, 2004
+# Based on contribution from Jonathan Swinton <jonathan at 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=='|')]
+             } else {
+                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))
+}
+
+"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) ) {
+      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 )" )
+    }
+  } else {
+    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 )" )
+    }
+  }
+  if (!is.numeric(value))
+    stop("\"digits\" must be numeric")
+  attr(x,"digits") <- value
+  return(x)
+}
+
+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")))))
+    stop("\"display\" must be in {\"d\",\"f\",\"e\",\"E\",\"g\",\"G\", \"fg\", \"s\"}")
+  attr(x,"display") <- value
+  return(x)
+}
+
+display <- function(x,...) UseMethod("display")
+display.xtable <- function(x,...) {
+  return(attr(x,"display",exact=TRUE))
+}
+
diff --git a/R/toLatex.R b/R/toLatex.R
new file mode 100644
index 0000000..b0a2e16
--- /dev/null
+++ b/R/toLatex.R
@@ -0,0 +1,40 @@
+### xtable package
+###
+### Produce LaTeX and HTML tables from R objects.
+###
+### Copyright 2000-2013 David B. Dahl <dahl at stat.byu.edu>
+###
+### Maintained by Charles Roosen <croosen at mango-solutions.com>
+###
+### This file is part of the `xtable' library for R and related languages.
+### It is made available under the terms of the GNU General Public
+### License, version 2, or at your option, any later version,
+### incorporated herein by reference.
+###
+### This program is distributed in the hope that it will be
+### useful, but WITHOUT ANY WARRANTY; without even the implied
+### warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+### PURPOSE.  See the GNU General Public License for more
+### details.
+###
+### You should have received a copy of the GNU General Public
+### License along with this program; if not, write to the Free
+### Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+### MA 02111-1307, USA
+
+## The generic for toLatex() is declared in the base package "utils"
+
+toLatex.xtable <- function(object, ...){
+  # Initially just capturing the output of print.xtable().  At some
+  # point this could be refactored to have print.xtable() call
+  # toLatex() instead. - CR, 30/01/2012
+  dotArgs <- list(...)
+  dotArgs$x <- object
+  dotArgs$type <- "latex"
+  dotArgs$print.results <- FALSE
+  z <- do.call("print.xtable", dotArgs)
+
+  z <- strsplit(z, split="\n")[[1]]
+  class(z) <- "Latex"
+  z
+}
diff --git a/R/xtable.R b/R/xtable.R
new file mode 100644
index 0000000..2afc43c
--- /dev/null
+++ b/R/xtable.R
@@ -0,0 +1,284 @@
+### xtable package
+###
+### Produce LaTeX and HTML tables from R objects.
+###
+### Copyright 2000-2013 David B. Dahl <dahl at stat.byu.edu>
+###
+### This file is part of the `xtable' library for R and related languages.
+### It is made available under the terms of the GNU General Public
+### License, version 2, or at your option, any later version,
+### incorporated herein by reference.
+###
+### This program is distributed in the hope that it will be
+### useful, but WITHOUT ANY WARRANTY; without even the implied
+### warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+### PURPOSE.  See the GNU General Public License for more
+### details.
+###
+### You should have received a copy of the GNU General Public
+### License along with this program; if not, write to the Free
+### Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+### MA 02111-1307, USA
+
+xtable <- function(x, caption = NULL, label = NULL, align = NULL,
+                   digits = NULL, display = NULL, ...) {
+  UseMethod("xtable")
+}
+
+
+## data.frame and matrix objects
+
+xtable.data.frame <- function(x, caption = NULL, label = NULL, align = NULL,
+                              digits = NULL, display = NULL, ...) {
+  logicals <- unlist(lapply(x, is.logical))
+  ##x[, logicals] <- lapply(x[, logicals], as.character)
+  ## Patch for logicals bug, no 1911
+  ## David Scott, <d.scott at auckland.ac.nz>, 2012-08-10
+  x[, logicals] <- lapply(x[, logicals, drop = FALSE], as.character)
+  characters <- unlist(lapply(x, is.character))
+  factors <- unlist(lapply(x, is.factor))
+  ints <- sapply(x, is.integer)
+  class(x) <- c("xtable","data.frame")
+  caption(x) <- caption
+  label(x) <- label
+  align(x) <- switch(1+is.null(align), align,
+                     c("r",c("r","l")[(characters|factors)+1]))
+  digits(x) <- switch(1+is.null(digits), digits, c(0,rep(2,ncol(x))))
+  ## Patch from Seth Falcon <sfalcon at fhcrc.org>, 18-May-2007
+  if (is.null(display)) {
+      display <- rep("f", ncol(x))
+      display[ints] <- "d"
+      display[characters | factors] <- "s"
+      display <- c("s", display)
+  }
+  display(x) <- display
+  return(x)
+}
+
+xtable.matrix <- function(x, caption = NULL, label = NULL, align = NULL,
+                          digits = NULL, display = NULL, ...) {
+  return(xtable.data.frame(data.frame(x, check.names = FALSE),
+                           caption = caption, label = label, align = align,
+                           digits = digits, display = display))
+}
+
+
+### 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,
+                       digits = NULL, display = NULL, ...) {
+  if (length(dim(x)) == 1) {
+    return(xtable.matrix(matrix(x,
+                                dimnames = list(rownames(x),
+                                                names(dimnames(x)))),
+                         caption = caption, label = label,
+                         align = align, digits = digits, display = display))
+  } 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))
+  } else {
+    stop("xtable.table is not implemented for tables of > 2 dimensions")
+  }
+}
+
+
+## anova objects
+
+xtable.anova <- function(x, caption = NULL, label = NULL, align = NULL,
+                         digits = NULL, display = NULL, ...) {
+  suggested.digits <- c(0,rep(2, ncol(x)))
+  suggested.digits[grep("Pr\\(>", names(x))+1] <- 4
+  suggested.digits[grep("P\\(>", names(x))+1] <- 4
+  suggested.digits[grep("Df", names(x))+1] <- 0
+
+  class(x) <- c("xtable","data.frame")
+  caption(x) <- caption
+  label(x) <- label
+  align(x) <- switch(1+is.null(align), align, c("l",rep("r", ncol(x))))
+  digits(x) <- switch(1+is.null(digits), digits, suggested.digits)
+  display(x) <- switch(1+is.null(display), display, c("s",rep("f", ncol(x))))
+  return(x)
+}
+
+
+## aov objects
+
+xtable.aov <- function(x, caption = NULL, label = NULL, align = NULL,
+                       digits = NULL, display = NULL, ...) {
+  return(xtable.anova(anova(x, ...), caption = caption, label = label,
+                      align = align, digits = digits, display = display))
+}
+
+xtable.summary.aov <- function(x, caption = NULL, label = NULL, align = NULL,
+                               digits = NULL, display = NULL, ...) {
+  return(xtable.anova(x[[1]], caption = caption, label = label,
+                      align = align, digits = digits, display = display))
+}
+
+xtable.summary.aovlist <- function(x, caption = NULL, label = NULL,
+                                   align = NULL,
+                                   digits = NULL, display = NULL, ...) {
+    for (i in 1:length(x)) {
+        if (i == 1) {
+            result <- xtable.summary.aov(x[[i]], caption = caption,
+                                         label = label,
+                                         align = align, digits = digits,
+                                         display = display)
+        } else {
+            result <- rbind(result,
+                            xtable.anova(x[[i]][[1]], caption = caption,
+                                         label = label, align = align,
+                                         digits = digits, display = display))
+        }
+    }
+    return(result)
+}
+
+xtable.aovlist <- function(x, caption = NULL, label = NULL, align = NULL,
+                           digits = NULL, display = NULL, ...) {
+  return(xtable.summary.aovlist(summary(x), caption = caption, label = label,
+                                align = align, digits = digits,
+                                display = display))
+}
+
+
+
+## lm objects
+
+xtable.lm <- function(x, caption = NULL, label = NULL, align = NULL,
+                      digits = NULL, display = NULL, ...) {
+  return(xtable.summary.lm(summary(x), caption = caption, label = label,
+                           align = align, digits = digits, display = display))
+}
+
+xtable.summary.lm <- function(x, caption = NULL, label = NULL, align = NULL,
+                              digits = NULL, display = NULL, ...) {
+  x <- data.frame(x$coef, check.names = FALSE)
+
+  class(x) <- c("xtable","data.frame")
+  caption(x) <- caption
+  label(x) <- label
+  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)
+}
+
+
+## glm objects
+
+xtable.glm <- function(x, caption = NULL, label = NULL, align = NULL,
+                       digits = NULL, display = NULL, ...) {
+  return(xtable.summary.glm(summary(x), caption = caption,
+                            label = label, align = align,
+                            digits = digits, display = display))
+}
+
+xtable.summary.glm <- function(x, caption = NULL, label = NULL, align = NULL,
+                               digits = NULL, display = NULL, ...) {
+  return(xtable.summary.lm(x, caption = caption, label = label,
+                           align = align, digits = digits, display = display))
+}
+
+
+## prcomp objects
+
+xtable.prcomp <- function(x, caption = NULL, label = NULL, align = NULL,
+                          digits = NULL, display = NULL, ...) {
+  x <- data.frame(x$rotation, check.names = FALSE)
+
+  class(x) <- c("xtable","data.frame")
+  caption(x) <- caption
+  label(x) <- label
+  align(x) <- switch(1+is.null(align), align, c("r",rep("r", ncol(x))))
+  digits(x) <- switch(1+is.null(digits), digits, c(0,rep(4, ncol(x))))
+  display(x) <- switch(1+is.null(display), display, c("s",rep("f", ncol(x))))
+  return(x)
+}
+
+xtable.summary.prcomp <- function(x, caption = NULL, label = NULL, align = NULL,
+                                  digits = NULL, display = NULL, ...) {
+  x <- data.frame(x$importance, check.names = FALSE)
+
+  class(x) <- c("xtable","data.frame")
+  caption(x) <- caption
+  label(x) <- label
+  align(x) <- switch(1+is.null(align), align, c("r",rep("r", ncol(x))))
+  digits(x) <- switch(1+is.null(digits), digits, c(0,rep(4, ncol(x))))
+  display(x) <- switch(1+is.null(display), display, c("s",rep("f", ncol(x))))
+  return(x)
+}
+
+
+# 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 at 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, ...)
+{
+  cox <- x
+  beta <- cox$coef
+  se <- sqrt(diag(cox$var))
+  if (is.null(cox$naive.var)) {
+    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 {
+    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))
+}
+
+# Additional method: xtable.ts
+# Contributed by David Mitchell (davidm at netspeed.com.au)
+# Date: July 2003
+xtable.ts <- function(x, caption = NULL, label = NULL, align = NULL,
+                      digits = NULL, display = NULL, ...) {
+  if (inherits(x, "ts") && !is.null(ncol(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")
+    ROWNAMES <- switch(frequency(x),
+                       tp.1,
+                       "Arg2", "Arg3",              # Dummy arguments
+                       paste(tp.1, c("Q1", "Q2", "Q3", "Q4")[tp.2], sep = " "),
+                       "Arg5", "Arg6",
+                       paste("Wk.", tp.1, " ", day.abb[tp.2], sep = ""),
+                       "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))) {
+    COLNAMES <- switch(frequency(x),
+                       "Value",
+                       "Arg2", "Arg3",              # Dummy arguments
+                       c("Q1", "Q2", "Q3", "Q4"),
+                       "Arg5", "Arg6",
+                       day.abb,
+                       "Arg8", "Arg9", "Arg10", "Arg11",
+                       month.abb)
+    ROWNAMES <- seq(from = start(x)[1], to = end(x)[1])
+    tmp <- data.frame(matrix(c(rep(NA, start(x)[2] - 1), x,
+                               rep(NA, frequency(x) - end(x)[2])),
+                             ncol = frequency(x), byrow = TRUE),
+                      row.names = ROWNAMES)
+    names(tmp) <- COLNAMES
+  }
+  return(xtable(tmp, caption = caption, label = label, align = align,
+                digits = digits, display = display))
+}
+
+# Suggested by Ajay Narottam Shah <ajayshah at mayin.org> in e-mail 2006/07/22
+xtable.zoo <- function(x, ...) {
+  return(xtable(as.ts(x), ...))
+}
+
diff --git a/build/vignette.rds b/build/vignette.rds
new file mode 100644
index 0000000..74f8018
Binary files /dev/null and b/build/vignette.rds differ
diff --git a/data/tli.txt.gz b/data/tli.txt.gz
new file mode 100644
index 0000000..64d5ba5
Binary files /dev/null and b/data/tli.txt.gz differ
diff --git a/inst/doc/margintable.R b/inst/doc/margintable.R
new file mode 100644
index 0000000..b4374a9
--- /dev/null
+++ b/inst/doc/margintable.R
@@ -0,0 +1,18 @@
+### R code from vignette source 'margintable.Rnw'
+
+###################################################
+### code chunk number 1: margintable.Rnw:52-55
+###################################################
+library(xtable)
+x <- matrix(rnorm(6), ncol = 2)
+x.small <- xtable(x, label = 'tabsmall', caption = 'A margin table')
+
+
+###################################################
+### code chunk number 2: margintable.Rnw:58-61
+###################################################
+print(x.small,floating.environment='margintable',
+      latex.environments = "",
+      table.placement = NULL)
+
+
diff --git a/inst/doc/margintable.Rnw b/inst/doc/margintable.Rnw
new file mode 100644
index 0000000..b12c583
--- /dev/null
+++ b/inst/doc/margintable.Rnw
@@ -0,0 +1,64 @@
+%\VignetteIndexEntry{xtable margintable}
+%\VignetteKeywords{LaTeX, HTML, table, margintable}
+
+
+\documentclass{tufte-handout}
+
+
+\title{
+A Margin Table Example
+}
+\author{David J. Scott}
+
+\usepackage{Sweave}
+\SweaveOpts{prefix.string=figdir/fig,debug=TRUE,eps=FALSE,echo=TRUE}
+\usepackage{rotating}
+\usepackage{longtable}
+\usepackage{booktabs}
+\usepackage{tabularx}
+\usepackage{hyperref}
+\usepackage{fancyvrb}
+\fvset{fontsize=\normalsize}
+
+\begin{document}
+
+\section{The Example}
+\label{sec:example}
+
+This document uses the Tufte handout \LaTeX\ document style. This is
+specified by the use of the document class as
+\Verb|\documentclass{tufte-handout}|.
+
+The Tufte-\LaTeX\ document classes define a style similar to the
+style Edward Tufte uses in his books and handouts.  Tufte's style is known
+for its extensive use of sidenotes, tight integration of graphics with
+text, and well-set typography.
+
+One of the most prominent and distinctive features of this style is the
+extensive use of sidenotes.  There is a wide margin to provide ample room
+for sidenotes and small figures.  Any \Verb|\footnote|s will automatically
+be converted to sidenotes.
+
+Here is an example of a margin table, suggested by Felix Sch\"onbrodt
+\Verb|<nicebread at gmx.net>|. I am not sure about its usefullness in
+practice however. Note that \Verb|latex.environments = ""| avoids the
+default option of tables being centered, which in this example would
+lead to the caption not being directly under the table. Most
+importantly, \Verb|table.placement = NULL| is required to ensure that
+the default table placement options \Verb|[ht]| being inserted after
+\Verb|\begin{margintable}|. This is necessary because the margintable
+  environment does not allow placement options like \Verb|[ht]|.
+
+<<>>=
+library(xtable)
+x <- matrix(rnorm(6), ncol = 2)
+x.small <- xtable(x, label = 'tabsmall', caption = 'A margin table')
+@
+
+<<results=tex>>=
+print(x.small,floating.environment='margintable',
+      latex.environments = "",
+      table.placement = NULL)
+@
+
+\end{document}
diff --git a/inst/doc/margintable.pdf b/inst/doc/margintable.pdf
new file mode 100644
index 0000000..4df077b
Binary files /dev/null and b/inst/doc/margintable.pdf differ
diff --git a/inst/doc/xtableGallery.R b/inst/doc/xtableGallery.R
new file mode 100644
index 0000000..cbd5474
--- /dev/null
+++ b/inst/doc/xtableGallery.R
@@ -0,0 +1,583 @@
+### R code from vignette source 'xtableGallery.snw'
+
+###################################################
+### code chunk number 1: xtableGallery.snw:14-20 (eval = FALSE)
+###################################################
+## makeme <- function() {
+## 	# I am a convenience function for debugging and can be ignored
+## 	setwd("C:/JonathanSwinton/PathwayModeling/src/R/SourcePackages/xtable/inst/doc")
+## 	Sweave("xtableGallery.RnW",stylepath=FALSE)
+## }
+## makeme()
+
+
+###################################################
+### code chunk number 2: xtableGallery.snw:45-46
+###################################################
+library(xtable)
+
+
+###################################################
+### code chunk number 3: xtableGallery.snw:52-57
+###################################################
+data(tli)
+
+## Demonstrate data.frame
+tli.table <- xtable(tli[1:10,])
+digits(tli.table)[c(2,6)] <- 0
+
+
+###################################################
+### code chunk number 4: xtableGallery.snw:59-60
+###################################################
+print(tli.table,floating=FALSE)
+
+
+###################################################
+### code chunk number 5: xtableGallery.snw:64-66
+###################################################
+design.matrix <- model.matrix(~ sex*grade, data=tli[1:10,])
+design.table <- xtable(design.matrix)
+
+
+###################################################
+### code chunk number 6: xtableGallery.snw:68-69
+###################################################
+print(design.table,floating=FALSE)
+
+
+###################################################
+### code chunk number 7: xtableGallery.snw:73-75
+###################################################
+fm1 <- aov(tlimth ~ sex + ethnicty + grade + disadvg, data=tli)
+fm1.table <- xtable(fm1)
+
+
+###################################################
+### code chunk number 8: xtableGallery.snw:77-78
+###################################################
+print(fm1.table,floating=FALSE)
+
+
+###################################################
+### code chunk number 9: xtableGallery.snw:81-83
+###################################################
+fm2 <- lm(tlimth ~ sex*ethnicty, data=tli)
+fm2.table <- xtable(fm2)
+
+
+###################################################
+### code chunk number 10: xtableGallery.snw:85-86
+###################################################
+print(fm2.table,floating=FALSE)
+
+
+###################################################
+### code chunk number 11: xtableGallery.snw:90-91
+###################################################
+print(xtable(anova(fm2)),floating=FALSE)
+
+
+###################################################
+### code chunk number 12: xtableGallery.snw:94-95
+###################################################
+fm2b <- lm(tlimth ~ ethnicty, data=tli)
+
+
+###################################################
+### code chunk number 13: xtableGallery.snw:97-98
+###################################################
+print(xtable(anova(fm2b,fm2)),floating=FALSE)
+
+
+###################################################
+### code chunk number 14: xtableGallery.snw:104-108
+###################################################
+
+## Demonstrate glm
+fm3 <- glm(disadvg ~ ethnicty*grade, data=tli, family=binomial())
+fm3.table <- xtable(fm3)
+
+
+###################################################
+### code chunk number 15: xtableGallery.snw:110-111
+###################################################
+print(fm3.table,floating=FALSE)
+
+
+###################################################
+### code chunk number 16: xtableGallery.snw:116-117
+###################################################
+print(xtable(anova(fm3)),floating=FALSE)
+
+
+###################################################
+### code chunk number 17: xtableGallery.snw:122-137
+###################################################
+
+## Demonstrate aov
+## Taken from help(aov) in R 1.1.1
+## From Venables and Ripley (1997) p.210.
+N <- c(0,1,0,1,1,1,0,0,0,1,1,0,1,1,0,0,1,0,1,0,1,1,0,0)
+P <- c(1,1,0,0,0,1,0,1,1,1,0,0,0,1,0,1,1,0,0,1,0,1,1,0)
+K <- c(1,0,0,1,0,1,1,0,0,1,0,1,0,1,1,0,0,0,1,1,1,0,1,0)
+yield <- c(49.5,62.8,46.8,57.0,59.8,58.5,55.5,56.0,62.8,55.8,69.5,55.0,
+           62.0,48.8,45.5,44.2,52.0,51.5,49.8,48.8,57.2,59.0,53.2,56.0)
+npk <- data.frame(block=gl(6,4), N=factor(N), P=factor(P), K=factor(K), yield=yield)
+npk.aov <- aov(yield ~ block + N*P*K, npk)
+op <- options(contrasts=c("contr.helmert", "contr.treatment"))
+npk.aovE <- aov(yield ~  N*P*K + Error(block), npk)
+options(op)
+#summary(npk.aov)
+
+
+###################################################
+### code chunk number 18: xtableGallery.snw:139-140
+###################################################
+print(xtable(npk.aov),floating=FALSE)
+
+
+###################################################
+### code chunk number 19: xtableGallery.snw:144-145
+###################################################
+print(xtable(anova(npk.aov)),floating=FALSE)
+
+
+###################################################
+### code chunk number 20: xtableGallery.snw:149-150
+###################################################
+print(xtable(summary(npk.aov)),floating=FALSE)
+
+
+###################################################
+### code chunk number 21: xtableGallery.snw:153-154
+###################################################
+#summary(npk.aovE)
+
+
+###################################################
+### code chunk number 22: xtableGallery.snw:156-157
+###################################################
+print(xtable(npk.aovE),floating=FALSE)
+
+
+###################################################
+### code chunk number 23: xtableGallery.snw:161-162
+###################################################
+print(xtable(summary(npk.aovE)),floating=FALSE)
+
+
+###################################################
+### code chunk number 24: xtableGallery.snw:166-176
+###################################################
+
+## Demonstrate lm
+## Taken from help(lm) in R 1.1.1
+## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
+## Page 9: Plant Weight Data.
+ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
+trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
+group <- gl(2,10,20, labels=c("Ctl","Trt"))
+weight <- c(ctl, trt)
+lm.D9 <- lm(weight ~ group)
+
+
+###################################################
+### code chunk number 25: xtableGallery.snw:178-179
+###################################################
+print(xtable(lm.D9),floating=FALSE)
+
+
+###################################################
+### code chunk number 26: xtableGallery.snw:183-184
+###################################################
+print(xtable(anova(lm.D9)),floating=FALSE)
+
+
+###################################################
+### code chunk number 27: xtableGallery.snw:188-198
+###################################################
+
+## Demonstrate glm
+## Taken from help(glm) in R 1.1.1
+## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
+## Page 93: Randomized Controlled Trial :
+counts <- c(18,17,15,20,10,20,25,13,12)
+outcome <- gl(3,1,9)
+treatment <- gl(3,3)
+d.AD <- data.frame(treatment, outcome, counts)
+glm.D93 <- glm(counts ~ outcome + treatment, family=poisson())
+
+
+###################################################
+### code chunk number 28: xtableGallery.snw:200-201
+###################################################
+print(xtable(glm.D93,align="r|llrc"),floating=FALSE)
+
+
+###################################################
+### code chunk number 29: prcomp
+###################################################
+if(require(stats,quietly=TRUE)) {
+  ## Demonstrate prcomp
+  ## Taken from help(prcomp) in mva package of R 1.1.1
+  data(USArrests)
+  pr1 <- prcomp(USArrests)
+}
+
+
+###################################################
+### code chunk number 30: xtableGallery.snw:213-216
+###################################################
+if(require(stats,quietly=TRUE)) {
+  print(xtable(pr1),floating=FALSE)
+}
+
+
+###################################################
+### code chunk number 31: xtableGallery.snw:221-222
+###################################################
+  print(xtable(summary(pr1)),floating=FALSE)
+
+
+###################################################
+### code chunk number 32: xtableGallery.snw:227-231
+###################################################
+#  ## Demonstrate princomp
+#  ## Taken from help(princomp) in mva package of R 1.1.1
+#  pr2 <- princomp(USArrests)
+#  print(xtable(pr2))
+
+
+###################################################
+### code chunk number 33: xtableGallery.snw:235-238
+###################################################
+temp.ts <- ts(cumsum(1+round(rnorm(100), 0)), start = c(1954, 7), frequency=12)
+   temp.table <- xtable(temp.ts,digits=0)
+    caption(temp.table) <- "Time series example"
+
+
+###################################################
+### code chunk number 34: xtableGallery.snw:240-241
+###################################################
+    print(temp.table,floating=FALSE)
+
+
+###################################################
+### code chunk number 35: savetofile
+###################################################
+if (FALSE) {
+  for(i in c("latex","html")) {
+    outFileName <- paste("xtable.",ifelse(i=="latex","tex",i),sep="")
+    print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environments=NULL)
+    print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environments="")
+    print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environments="center")
+    print(xtable(anova(glm.D93,test="Chisq")),type=i,file=outFileName,append=TRUE)
+    print(xtable(anova(glm.D93)),hline.after=c(1),size="small",type=i,file=outFileName,append=TRUE)
+      # print(xtable(pr2),type=i,file=outFileName,append=TRUE)
+         }
+}
+
+
+###################################################
+### code chunk number 36: xtableGallery.snw:258-261
+###################################################
+insane <- data.frame(Name=c("Ampersand","Greater than","Less than","Underscore","Per cent","Dollar","Backslash","Hash", "Caret", "Tilde","Left brace","Right brace"),
+				Character = I(c("&",">",		"<",		"_",		"%",		"$",		"\\", "#",	"^",		"~","{","}")))
+colnames(insane)[2] <- paste(insane[,2],collapse="")
+
+
+###################################################
+### code chunk number 37: pxti
+###################################################
+print( xtable(insane))
+
+
+###################################################
+### code chunk number 38: xtableGallery.snw:268-269
+###################################################
+wanttex <- xtable(data.frame( label=paste("Value_is $10^{-",1:3,"}$",sep="")))
+
+
+###################################################
+### code chunk number 39: xtableGallery.snw:271-272
+###################################################
+print(wanttex,sanitize.text.function=function(str)gsub("_","\\_",str,fixed=TRUE))
+
+
+###################################################
+### code chunk number 40: xtableGallery.snw:279-283
+###################################################
+mat <- round(matrix(c(0.9, 0.89, 200, 0.045, 2.0), c(1, 5)), 4)
+rownames(mat) <- "$y_{t-1}$"
+colnames(mat) <- c("$R^2$", "$\\bar{R}^2$", "F-stat", "S.E.E", "DW")
+mat <- xtable(mat)
+
+
+###################################################
+### code chunk number 41: xtableGallery.snw:285-286
+###################################################
+print(mat, sanitize.text.function = function(x){x})
+
+
+###################################################
+### code chunk number 42: xtableGallery.snw:291-292
+###################################################
+money <- matrix(c("$1,000","$900","$100"),ncol=3,dimnames=list("$\\alpha$",c("Income (US$)","Expenses (US$)","Profit (US$)")))
+
+
+###################################################
+### code chunk number 43: xtableGallery.snw:294-295
+###################################################
+print(xtable(money),sanitize.rownames.function=function(x) {x})
+
+
+###################################################
+### code chunk number 44: xtableGallery.snw:300-303
+###################################################
+   print(xtable(lm.D9,caption="\\tt latex.environments=NULL"),latex.environments=NULL)
+    print(xtable(lm.D9,caption="\\tt latex.environments=\"\""),latex.environments="")
+    print(xtable(lm.D9,caption="\\tt latex.environments=\"center\""),latex.environments="center")
+
+
+###################################################
+### code chunk number 45: xtableGallery.snw:307-308
+###################################################
+tli.table <- xtable(tli[1:10,])
+
+
+###################################################
+### code chunk number 46: xtableGallery.snw:310-311
+###################################################
+align(tli.table) <- rep("r",6)
+
+
+###################################################
+### code chunk number 47: xtableGallery.snw:313-314
+###################################################
+print(tli.table,floating=FALSE)
+
+
+###################################################
+### code chunk number 48: xtableGallery.snw:317-318
+###################################################
+align(tli.table) <- "|rrl|l|lr|"
+
+
+###################################################
+### code chunk number 49: xtableGallery.snw:320-321
+###################################################
+print(tli.table,floating=FALSE)
+
+
+###################################################
+### code chunk number 50: xtableGallery.snw:324-325
+###################################################
+align(tli.table) <- "|rr|lp{3cm}l|r|"
+
+
+###################################################
+### code chunk number 51: xtableGallery.snw:327-328
+###################################################
+print(tli.table,floating=FALSE)
+
+
+###################################################
+### code chunk number 52: xtableGallery.snw:335-336
+###################################################
+digits(tli.table) <- 3
+
+
+###################################################
+### code chunk number 53: xtableGallery.snw:338-339
+###################################################
+print(tli.table,floating=FALSE,)
+
+
+###################################################
+### code chunk number 54: xtableGallery.snw:344-345
+###################################################
+digits(tli.table) <- 1:(ncol(tli)+1)
+
+
+###################################################
+### code chunk number 55: xtableGallery.snw:347-348
+###################################################
+print(tli.table,floating=FALSE,)
+
+
+###################################################
+### code chunk number 56: xtableGallery.snw:353-354
+###################################################
+digits(tli.table) <- matrix( 0:4, nrow = 10, ncol = ncol(tli)+1 )
+
+
+###################################################
+### code chunk number 57: xtableGallery.snw:356-357
+###################################################
+print(tli.table,floating=FALSE,)
+
+
+###################################################
+### code chunk number 58: xtableGallery.snw:361-362
+###################################################
+print((tli.table),include.rownames=FALSE,floating=FALSE)
+
+
+###################################################
+### code chunk number 59: xtableGallery.snw:366-367
+###################################################
+align(tli.table) <- "|r|r|lp{3cm}l|r|"
+
+
+###################################################
+### code chunk number 60: xtableGallery.snw:369-370
+###################################################
+print((tli.table),include.rownames=FALSE,floating=FALSE)
+
+
+###################################################
+### code chunk number 61: xtableGallery.snw:374-375
+###################################################
+align(tli.table) <- "|rr|lp{3cm}l|r|"
+
+
+###################################################
+### code chunk number 62: xtableGallery.snw:379-380
+###################################################
+print((tli.table),include.colnames=FALSE,floating=FALSE)
+
+
+###################################################
+### code chunk number 63: xtableGallery.snw:384-385
+###################################################
+print(tli.table,include.colnames=FALSE,floating=FALSE,hline.after=c(0,nrow(tli.table)))
+
+
+###################################################
+### code chunk number 64: xtableGallery.snw:389-390
+###################################################
+print((tli.table),include.colnames=FALSE,include.rownames=FALSE,floating=FALSE)
+
+
+###################################################
+### code chunk number 65: xtableGallery.snw:397-398
+###################################################
+print((tli.table),rotate.rownames=TRUE,rotate.colnames=TRUE)
+
+
+###################################################
+### code chunk number 66: xtableGallery.snw:407-408
+###################################################
+print(xtable(anova(glm.D93)),hline.after=c(1),floating=FALSE)
+
+
+###################################################
+### code chunk number 67: xtableGallery.snw:436-437
+###################################################
+print(tli.table, booktabs=TRUE, floating = FALSE)
+
+
+###################################################
+### code chunk number 68: xtableGallery.snw:449-451
+###################################################
+bktbs <- xtable(matrix(1:10, ncol = 2))
+hlines <- c(-1,0,1,nrow(bktbs))
+
+
+###################################################
+### code chunk number 69: xtableGallery.snw:454-455
+###################################################
+print(bktbs, booktabs = TRUE, hline.after = hlines, floating = FALSE)
+
+
+###################################################
+### code chunk number 70: xtableGallery.snw:460-461
+###################################################
+print(xtable(anova(glm.D93)),size="small",floating=FALSE)
+
+
+###################################################
+### code chunk number 71: longtable
+###################################################
+
+## Demonstration of longtable support.
+x <- matrix(rnorm(1000), ncol = 10)
+x.big <- xtable(x,label='tabbig',
+	caption='Example of longtable spanning several pages')
+
+
+###################################################
+### code chunk number 72: xtableGallery.snw:475-476
+###################################################
+print(x.big,tabular.environment='longtable',floating=FALSE)
+
+
+###################################################
+### code chunk number 73: xtableGallery.snw:514-516
+###################################################
+x <- x[1:30,]
+x.small <- xtable(x,label='tabsmall',caption='A sideways table')
+
+
+###################################################
+### code chunk number 74: xtableGallery.snw:519-520
+###################################################
+print(x.small,floating.environment='sidewaystable')
+
+
+###################################################
+### code chunk number 75: xtableGallery.snw:527-529
+###################################################
+x <- x[1:20,]
+x.rescale <- xtable(x,label='tabrescaled',caption='A rescaled table')
+
+
+###################################################
+### code chunk number 76: xtableGallery.snw:532-533
+###################################################
+print(x.rescale, scalebox=0.7)
+
+
+###################################################
+### code chunk number 77: xtableGallery.snw:542-552
+###################################################
+df.width <- data.frame(
+  "label 1 with much more text than is needed" = c("item 1", "A"),
+  "label 2 is also very long" = c("item 2","B"),
+  "label 3" = c("item 3","C"),
+  "label 4" = c("item 4 but again with too much text","D"),
+  check.names = FALSE)
+
+x.width <- xtable(df.width,
+  caption="Using the 'tabularx' environment")
+align(x.width) <- "|l|X|X|l|X|"
+
+
+###################################################
+### code chunk number 78: xtableGallery.snw:555-557
+###################################################
+print(x.width, tabular.environment="tabularx",
+  width="\\textwidth")
+
+
+###################################################
+### code chunk number 79: xtableGallery.snw:565-566
+###################################################
+x.out <- print(tli.table, print.results = FALSE)
+
+
+###################################################
+### code chunk number 80: xtableGallery.snw:573-576
+###################################################
+x.ltx <- toLatex(tli.table)
+class(x.ltx)
+x.ltx
+
+
+###################################################
+### code chunk number 81: xtableGallery.snw:582-583
+###################################################
+toLatex(sessionInfo())
+
+
diff --git a/inst/doc/xtableGallery.pdf b/inst/doc/xtableGallery.pdf
new file mode 100644
index 0000000..bd71bc0
Binary files /dev/null and b/inst/doc/xtableGallery.pdf differ
diff --git a/inst/doc/xtableGallery.snw b/inst/doc/xtableGallery.snw
new file mode 100644
index 0000000..2dfa32b
--- /dev/null
+++ b/inst/doc/xtableGallery.snw
@@ -0,0 +1,585 @@
+%\VignetteIndexEntry{xtable Gallery}
+%\VignetteDepends{xtable}
+%\VignetteKeywords{LaTeX,HTML,table}
+%\VignettePackage{xtable}
+
+%**************************************************************************
+%
+% # $Id:$
+
+% $Revision:  $
+% $Author: $
+% $Date:  $
+
+<<echo=FALSE,eval=FALSE>>=
+makeme <- function() {
+	# I am a convenience function for debugging and can be ignored
+	setwd("C:/JonathanSwinton/PathwayModeling/src/R/SourcePackages/xtable/inst/doc")
+	Sweave("xtableGallery.RnW",stylepath=FALSE)
+}
+makeme()
+@
+
+\documentclass[letterpaper]{article}
+
+\title{
+The xtable gallery
+}
+\author{Jonathan Swinton <jonathan at swintons.net>\\ with small contributions from others}
+
+\usepackage{Sweave}
+\SweaveOpts{prefix.string=figdir/fig,debug=TRUE,eps=FALSE,echo=TRUE}
+\usepackage{rotating}
+\usepackage{longtable}
+\usepackage{booktabs}
+\usepackage{tabularx}
+%\usepackage{hyperref}
+\begin{document}
+
+\maketitle
+\section{Summary}
+This document gives a gallery of tables which can be made
+by using the {\tt xtable} package to create \LaTeX\ output.
+It doubles as a regression check for the package.
+
+<<>>=
+library(xtable)
+@
+
+\section{Gallery}
+\subsection{Data frame}
+Load example dataset
+<<>>=
+data(tli)
+
+## Demonstrate data.frame
+tli.table <- xtable(tli[1:10,])
+digits(tli.table)[c(2,6)] <- 0
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE)
+@
+
+\subsection{Matrix}
+<<>>=
+design.matrix <- model.matrix(~ sex*grade, data=tli[1:10,])
+design.table <- xtable(design.matrix)
+@
+<<results=tex>>=
+print(design.table,floating=FALSE)
+@
+
+\subsection{aov}
+<<>>=
+fm1 <- aov(tlimth ~ sex + ethnicty + grade + disadvg, data=tli)
+fm1.table <- xtable(fm1)
+@
+<<results=tex>>=
+print(fm1.table,floating=FALSE)
+@
+\subsection{lm}
+<<>>=
+fm2 <- lm(tlimth ~ sex*ethnicty, data=tli)
+fm2.table <- xtable(fm2)
+@
+<<results=tex>>=
+print(fm2.table,floating=FALSE)
+@
+\subsubsection{anova object}
+
+<<results=tex>>=
+print(xtable(anova(fm2)),floating=FALSE)
+@
+\subsubsection{Another anova object}
+<<>>=
+fm2b <- lm(tlimth ~ ethnicty, data=tli)
+@
+<<results=tex>>=
+print(xtable(anova(fm2b,fm2)),floating=FALSE)
+@
+
+
+\subsection{glm}
+
+<<>>=
+
+## Demonstrate glm
+fm3 <- glm(disadvg ~ ethnicty*grade, data=tli, family=binomial())
+fm3.table <- xtable(fm3)
+@
+<<results=tex>>=
+print(fm3.table,floating=FALSE)
+@
+
+\subsubsection{anova object}
+@
+<<results=tex>>=
+print(xtable(anova(fm3)),floating=FALSE)
+@
+
+
+\subsection{More aov}
+<<>>=
+
+## Demonstrate aov
+## Taken from help(aov) in R 1.1.1
+## From Venables and Ripley (1997) p.210.
+N <- c(0,1,0,1,1,1,0,0,0,1,1,0,1,1,0,0,1,0,1,0,1,1,0,0)
+P <- c(1,1,0,0,0,1,0,1,1,1,0,0,0,1,0,1,1,0,0,1,0,1,1,0)
+K <- c(1,0,0,1,0,1,1,0,0,1,0,1,0,1,1,0,0,0,1,1,1,0,1,0)
+yield <- c(49.5,62.8,46.8,57.0,59.8,58.5,55.5,56.0,62.8,55.8,69.5,55.0,
+           62.0,48.8,45.5,44.2,52.0,51.5,49.8,48.8,57.2,59.0,53.2,56.0)
+npk <- data.frame(block=gl(6,4), N=factor(N), P=factor(P), K=factor(K), yield=yield)
+npk.aov <- aov(yield ~ block + N*P*K, npk)
+op <- options(contrasts=c("contr.helmert", "contr.treatment"))
+npk.aovE <- aov(yield ~  N*P*K + Error(block), npk)
+options(op)
+#summary(npk.aov)
+@
+<<results=tex>>=
+print(xtable(npk.aov),floating=FALSE)
+@
+
+\subsubsection{anova object}
+<<results=tex>>=
+print(xtable(anova(npk.aov)),floating=FALSE)
+@
+
+\subsubsection{Another anova object}
+<<results=tex>>=
+print(xtable(summary(npk.aov)),floating=FALSE)
+@
+
+<<>>=
+#summary(npk.aovE)
+@
+<<results=tex>>=
+print(xtable(npk.aovE),floating=FALSE)
+@
+
+
+<<results=tex>>=
+print(xtable(summary(npk.aovE)),floating=FALSE)
+@
+
+\subsection{More lm}
+<<>>=
+
+## Demonstrate lm
+## Taken from help(lm) in R 1.1.1
+## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
+## Page 9: Plant Weight Data.
+ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
+trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
+group <- gl(2,10,20, labels=c("Ctl","Trt"))
+weight <- c(ctl, trt)
+lm.D9 <- lm(weight ~ group)
+@
+<<results=tex>>=
+print(xtable(lm.D9),floating=FALSE)
+@
+
+
+<<results=tex>>=
+print(xtable(anova(lm.D9)),floating=FALSE)
+@
+
+\subsection{More glm}
+<<>>=
+
+## Demonstrate glm
+## Taken from help(glm) in R 1.1.1
+## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
+## Page 93: Randomized Controlled Trial :
+counts <- c(18,17,15,20,10,20,25,13,12)
+outcome <- gl(3,1,9)
+treatment <- gl(3,3)
+d.AD <- data.frame(treatment, outcome, counts)
+glm.D93 <- glm(counts ~ outcome + treatment, family=poisson())
+@
+<<results=tex>>=
+print(xtable(glm.D93,align="r|llrc"),floating=FALSE)
+@
+
+\subsection{prcomp}
+<<prcomp>>=
+if(require(stats,quietly=TRUE)) {
+  ## Demonstrate prcomp
+  ## Taken from help(prcomp) in mva package of R 1.1.1
+  data(USArrests)
+  pr1 <- prcomp(USArrests)
+}
+@
+<<results=tex>>=
+if(require(stats,quietly=TRUE)) {
+  print(xtable(pr1),floating=FALSE)
+}
+@
+
+
+@
+<<results=tex>>=
+  print(xtable(summary(pr1)),floating=FALSE)
+@
+
+
+
+<<>>=
+#  ## Demonstrate princomp
+#  ## Taken from help(princomp) in mva package of R 1.1.1
+#  pr2 <- princomp(USArrests)
+#  print(xtable(pr2))
+@
+\subsection{Time series}
+
+<<>>=
+temp.ts <- ts(cumsum(1+round(rnorm(100), 0)), start = c(1954, 7), frequency=12)
+   temp.table <- xtable(temp.ts,digits=0)
+    caption(temp.table) <- "Time series example"
+@
+<<results=tex>>=
+    print(temp.table,floating=FALSE)
+@
+<<savetofile,echo=FALSE>>=
+if (FALSE) {
+  for(i in c("latex","html")) {
+    outFileName <- paste("xtable.",ifelse(i=="latex","tex",i),sep="")
+    print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environments=NULL)
+    print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environments="")
+    print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environments="center")
+    print(xtable(anova(glm.D93,test="Chisq")),type=i,file=outFileName,append=TRUE)
+    print(xtable(anova(glm.D93)),hline.after=c(1),size="small",type=i,file=outFileName,append=TRUE)
+      # print(xtable(pr2),type=i,file=outFileName,append=TRUE)
+         }
+}
+@
+
+\section{Sanitization}
+<<>>=
+insane <- data.frame(Name=c("Ampersand","Greater than","Less than","Underscore","Per cent","Dollar","Backslash","Hash", "Caret", "Tilde","Left brace","Right brace"),
+				Character = I(c("&",">",		"<",		"_",		"%",		"$",		"\\", "#",	"^",		"~","{","}")))
+colnames(insane)[2] <- paste(insane[,2],collapse="")
+@
+
+<<pxti,results=tex>>=
+print( xtable(insane))
+@
+Sometimes you might want to have your own sanitization function
+<<>>=
+wanttex <- xtable(data.frame( label=paste("Value_is $10^{-",1:3,"}$",sep="")))
+@
+<<results=tex>>=
+print(wanttex,sanitize.text.function=function(str)gsub("_","\\_",str,fixed=TRUE))
+@
+
+\subsection{Markup in tables}
+
+Markup can be kept in tables, including column and row names, by using a custom sanitize.text.function:
+
+<<>>=
+mat <- round(matrix(c(0.9, 0.89, 200, 0.045, 2.0), c(1, 5)), 4)
+rownames(mat) <- "$y_{t-1}$"
+colnames(mat) <- c("$R^2$", "$\\bar{R}^2$", "F-stat", "S.E.E", "DW")
+mat <- xtable(mat)
+@
+<<results=tex>>=
+print(mat, sanitize.text.function = function(x){x})
+@
+
+% By David Dahl to demonstrate contribution from David Whitting, 2007-10-09.
+You can also have sanitize functions that are specific to column or row names.  In the table below, the row name is not sanitized but column names and table elements are:
+<<>>=
+money <- matrix(c("$1,000","$900","$100"),ncol=3,dimnames=list("$\\alpha$",c("Income (US$)","Expenses (US$)","Profit (US$)")))
+@
+<<results=tex>>=
+print(xtable(money),sanitize.rownames.function=function(x) {x})
+@
+
+\section{Format examples}
+\subsection{Adding a centering environment }
+<<results=tex>>=
+   print(xtable(lm.D9,caption="\\tt latex.environments=NULL"),latex.environments=NULL)
+    print(xtable(lm.D9,caption="\\tt latex.environments=\"\""),latex.environments="")
+    print(xtable(lm.D9,caption="\\tt latex.environments=\"center\""),latex.environments="center")
+@
+\subsection{Column alignment}
+
+<<>>=
+tli.table <- xtable(tli[1:10,])
+@
+<<>>=
+align(tli.table) <- rep("r",6)
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE)
+@
+\subsubsection{Single string and column lines}
+<<>>=
+align(tli.table) <- "|rrl|l|lr|"
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE)
+@
+\subsubsection{Fixed width columns}
+<<>>=
+align(tli.table) <- "|rr|lp{3cm}l|r|"
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE)
+@
+
+\subsection{Significant digits}
+
+
+Specify with a single argument
+<<>>=
+digits(tli.table) <- 3
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE,)
+@
+
+
+or one for each column, counting the row names
+<<>>=
+digits(tli.table) <- 1:(ncol(tli)+1)
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE,)
+@
+
+
+or as a full matrix
+<<>>=
+digits(tli.table) <- matrix( 0:4, nrow = 10, ncol = ncol(tli)+1 )
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE,)
+@
+
+\subsection{Suppress row names}
+<<results=tex>>=
+print((tli.table),include.rownames=FALSE,floating=FALSE)
+@
+
+If you want a vertical line on the left, you need to change the align attribute.
+<<>>=
+align(tli.table) <- "|r|r|lp{3cm}l|r|"
+@
+<<results=tex>>=
+print((tli.table),include.rownames=FALSE,floating=FALSE)
+@
+
+Revert the alignment to what is was before.
+<<>>=
+align(tli.table) <- "|rr|lp{3cm}l|r|"
+@
+
+\subsection{Suppress column names}
+<<results=tex>>=
+print((tli.table),include.colnames=FALSE,floating=FALSE)
+@
+\\
+Note the doubled header lines which can be suppressed with, eg,
+<<results=tex>>=
+print(tli.table,include.colnames=FALSE,floating=FALSE,hline.after=c(0,nrow(tli.table)))
+@
+
+\subsection{Suppress row and column names}
+<<results=tex>>=
+print((tli.table),include.colnames=FALSE,include.rownames=FALSE,floating=FALSE)
+@
+
+\subsection{Rotate row and column names}
+The {\tt rotate.rownames } and {\tt rotate.colnames} arguments can be
+used to rotate the row and/or column names.
+
+<<results=tex>>=
+print((tli.table),rotate.rownames=TRUE,rotate.colnames=TRUE)
+@
+
+\subsection{Horizontal lines}
+
+\subsubsection{Line locations}
+
+Use the {\tt hline.after} argument to specify the position of the horizontal lines.
+
+<<results=tex>>=
+print(xtable(anova(glm.D93)),hline.after=c(1),floating=FALSE)
+@
+
+\subsubsection{Line styles}
+
+The \LaTeX package {\tt booktabs} can be used to specify different
+line style tags for top, middle, and bottom lines.  Specifying
+{\tt booktabs = TRUE} will lead to separate tags being generated
+for the three line types.
+
+Insert \verb|\usepackage{booktabs}| in your \LaTeX preamble and define
+the {\tt toprule}, {\tt midrule}, and {\tt bottomrule} tags to specify
+the line styles. By default, when no value is given for
+\texttt{hline.after}, a \texttt{toprule} will be drawn above the
+table, a \texttt{midrule} after the table headings and a
+\texttt{bottomrule} below the table. The width of the top and bottom
+rules can be set by supplying a value to \verb+\heavyrulewidth+. The
+width of the midrules can be set by supplying a value to
+\verb+\lightrulewidth+. The following tables have
+\verb+\heavyrulewidth = 2pt+ and \verb+\lightrulewidth = 0.5pt+, to
+ensure the difference in weight is noticeable.
+
+There is no support for \verb+\cmidrule+ or \verb+\specialrule+
+although they are part of the \texttt{booktabs} package.
+
+\heavyrulewidth = 2pt
+\lightrulewidth = 0.5pt
+
+<<results=tex>>=
+print(tli.table, booktabs=TRUE, floating = FALSE)
+@
+
+\vspace{12pt}
+If \texttt{hline.after} includes $-1$, a \texttt{toprule} will be
+drawn above the table. If \texttt{hline.after} includes the number of
+rows in the table, a \texttt{bottomrule} will be drawn below the
+table. For any other values specified in \texttt{hline.after}, a
+\texttt{midrule} will be drawn after that line of the table.
+
+The next table has more than one \texttt{midrule}.
+
+<<>>=
+bktbs <- xtable(matrix(1:10, ncol = 2))
+hlines <- c(-1,0,1,nrow(bktbs))
+@
+This command produces the required table.
+<<results=tex>>=
+print(bktbs, booktabs = TRUE, hline.after = hlines, floating = FALSE)
+@
+
+
+\subsection{Table-level \LaTeX}
+<<results=tex>>=
+print(xtable(anova(glm.D93)),size="small",floating=FALSE)
+@
+
+
+\subsection{Long tables}
+Remember to insert \verb|\usepackage{longtable}| in your \LaTeX preamble.
+
+<<longtable>>=
+
+## Demonstration of longtable support.
+x <- matrix(rnorm(1000), ncol = 10)
+x.big <- xtable(x,label='tabbig',
+	caption='Example of longtable spanning several pages')
+@
+<<results=tex>>=
+print(x.big,tabular.environment='longtable',floating=FALSE)
+@
+
+%%
+%% The column name alignment is off in the following example.
+%% It needs some revision before exposing it. - CR, 7/2/2012
+%%
+%
+%\subsubsection{Long tables with the header on each page}
+%
+%The {\tt add.to.row} argument can be used to display the header
+%for a long table on each page, and to add a "continued" footer
+%on all pages except the last page.
+%
+%<<results=tex>>=
+%library(xtable)
+%x<-matrix(rnorm(1000), ncol = 10)
+%addtorow<-list()
+%addtorow$pos<-list()
+%addtorow$pos[[1]]<-c(0)
+%addtorow$command<-c(paste(
+%    "\\hline \n",
+%    "  \\endhead \n",
+%    "  \\hline \n",
+%    "  {\\footnotesize Continued on next page} \n",
+%    "  \\endfoot \n",
+%    "  \\endlastfoot \n",sep=""))
+%x.big2 <- xtable(x, label = "tabbig2",
+%    caption = "Example of longtable with the header on each page")
+%print(x.big2, tabular.environment = "longtable", floating = FALSE,
+%include.rownames=FALSE, add.to.row=addtorow, hline.after=c(-1) )
+%@
+
+\subsection{Sideways tables}
+Remember to insert \verb|\usepackage{rotating}| in your LaTeX preamble.
+Sideways tables can't be forced in place with the `H' specifier, but you can
+use the \verb|\clearpage| command to get them fairly nearby.
+
+<<>>=
+x <- x[1:30,]
+x.small <- xtable(x,label='tabsmall',caption='A sideways table')
+@
+
+<<results=tex>>=
+print(x.small,floating.environment='sidewaystable')
+@
+\clearpage
+
+\subsection{Rescaled tables}
+Specify a {\tt scalebox} value to rescale the table.
+
+<<>>=
+x <- x[1:20,]
+x.rescale <- xtable(x,label='tabrescaled',caption='A rescaled table')
+@
+
+<<results=tex>>=
+print(x.rescale, scalebox=0.7)
+@
+
+\subsection{Table Width}
+The {\tt tabularx} tabular environment provides more alignment options,
+and has a {\tt width} argument to specify the table width.
+
+Remember to insert \verb|\usepackage{tabularx}| in your \LaTeX preamble.
+
+<<>>=
+df.width <- data.frame(
+  "label 1 with much more text than is needed" = c("item 1", "A"),
+  "label 2 is also very long" = c("item 2","B"),
+  "label 3" = c("item 3","C"),
+  "label 4" = c("item 4 but again with too much text","D"),
+  check.names = FALSE)
+
+x.width <- xtable(df.width,
+  caption="Using the 'tabularx' environment")
+align(x.width) <- "|l|X|X|l|X|"
+@
+
+<<results=tex>>=
+print(x.width, tabular.environment="tabularx",
+  width="\\textwidth")
+@
+
+\section{Suppressing Printing}
+By default the {\tt print} method will print the LaTeX or HTML to standard
+output and also return the character strings invisibly.  The printing to
+standard output can be suppressed by specifying {\tt print.results = FALSE}.
+
+<<>>=
+x.out <- print(tli.table, print.results = FALSE)
+@
+
+Formatted output can also be captured without printing with the
+{\tt toLatex} method.  This function returns an object of class
+{\tt "Latex"}.
+
+<<>>=
+x.ltx <- toLatex(tli.table)
+class(x.ltx)
+x.ltx
+@
+
+\section{Acknowledgements}
+Most of the examples in this gallery are taken from the {\tt xtable} documentation.
+\section{R Session information}
+<<results=tex>>=
+toLatex(sessionInfo())
+@
+\end{document}
diff --git a/man/print.xtable.Rd b/man/print.xtable.Rd
new file mode 100644
index 0000000..aeda298
--- /dev/null
+++ b/man/print.xtable.Rd
@@ -0,0 +1,242 @@
+\name{print.xtable}
+\alias{print.xtable}
+\title{Print Export Tables}
+\description{
+  Function returning and displaying or writing to disk the LaTeX or HTML
+  code associated with the supplied object of class \code{xtable}.
+}
+\usage{
+\method{print}{xtable}(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", c(-1,0,nrow(x))),
+  NA.string = getOption("xtable.NA.string", ""),
+  include.rownames = getOption("xtable.include.rownames", TRUE),
+  include.colnames = getOption("xtable.include.colnames", TRUE),
+  only.contents = getOption("xtable.only.contents", FALSE),
+  add.to.row = getOption("xtable.add.to.row", NULL),
+  sanitize.text.function = getOption("xtable.sanitize.text.function", NULL),
+  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),
+  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}{An object of class \code{"xtable"}.}
+  \item{type}{Type of table to produce.  Possible values for \code{type}
+    are \code{"latex"} or \code{"html"}.
+    Default value is \code{"latex"}.}
+  \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 have 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 specificed 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.
+    Defaults to \code{"tabular"}.
+    When working with tables that extend more than one page, using
+    \code{tabular.environment="longtable"} and the LaTeX package
+    \code{"longtable"} (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.}
+  \item{size}{An arbitrary character vector intended to be used to set
+    the font size in a LaTeX table.  The supplied value (if not
+    \code{NULL}) is inserted just before the tabular environment
+    starts.
+    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.  If \code{NULL} is used
+    no lines are produced.
+    Default value is \code{c(-1,0,nrow(x))} which means draw a line
+    before and after the columns names and at the end of the
+    table. Repeated values are allowed.}
+  \item{NA.string}{String to be used for missing values in table
+    entries.
+    Default value is \code{""}.}
+  \item{include.rownames}{logical. If \code{TRUE} the rows names is
+    printed.
+    Default value is \code{TRUE}.}
+  \item{include.colnames}{logical. If \code{TRUE} the columns names is
+    printed.
+    Default value is \code{TRUE}.}
+  \item{only.contents}{logical. If \code{TRUE} only the rows of the
+    table is 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 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 of 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}{All non-numeric enteries (except row and
+    column names) are sanitised in an attempt to remove characters which
+    have special meaning for the output format. If
+    \code{sanitize.text.function} is not NULL (the default), it should
+    be a function taking a character vector and returning one, and will
+    be used for the sanitization instead of the default internal
+    function.}
+  \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{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.}
+  \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 =
+      ","))}. \code{digits} and \code{format} arguments should not be
+    included in this list. See details. }
+  \item{rotate.rownames}{If \code{TRUE}, the row names are displayed
+    vertically in LaTeX. }
+  \item{rotate.colnames}{If \code{TRUE}, the column names are displayed
+    vertically in LaTeX. }
+  \item{booktabs}{If \code{TRUE}, the \code{toprule}, \code{midrule} and
+    \code{bottomrule} tags from the LaTex "booktabs" package are used
+    rather than \code{hline} for the horizontal line tags. }
+  \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. }
+  \item{width}{If not \code{NULL}, the specified value is included in
+    parenthesis 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. }
+  \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{
+  This function displays or writes to disk the code to produce a table
+  associated with an object \code{x} of class \code{"xtable"}.
+  The resulting code is either a LaTeX or HTML table, depending on the
+  value of \code{type}.  The function also (invisibly) returns a
+  character vector of the results (which can be helpful for
+  post-processing).
+
+  Since version 1.4 the non default behavior of \code{hline.after} is
+  changed. To obtain the same results as the previous versions add to
+  the \code{hline.after} vector the vector \code{c(-1, 0, nrow(x))}
+  where \code{nrow(x)} is the numbers of rows of the object.
+
+  From version 1.4-3, all non-numeric columns are sanitized, and all
+  LaTeX special characters are sanitised for LaTeX output.  See Section
+  3 of the \code{xtableGallery} vignette for an example of customising
+  the sanitization. From version 1.4-4, the sanitization also applies to
+  column names.  To remove any text sanitization, specify
+  \code{sanitize.text.function=function(x){x}}.
+
+  From version 1.6-1 the default values for the arguments other than
+  \code{x} are obtainined using \code{getOption()}.  Hence the user can
+  set the values once with \code{options()} rather than setting them in
+  every call to \code{print.xtable()}.
+
+  The argument \code{format.args} is used to supply arguments to the
+  \code{formatC} function, but will throw an error if values for
+  \code{digits} or \code{format} are included in the list of
+  arguments. The recommended approach is to specify \code{digits} supply
+  the argument \code{digits} to \code{xtable}, and to specify
+  \code{format} supply the argument \code{display} to \code{xtable}. See
+  the examples.
+}
+\author{
+  David Dahl \email{dahl at stat.byu.edu} with contributions and
+  suggestions from many others (see source code).
+}
+\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}
+}
+\seealso{
+  \code{\link{xtable}}, \code{\link{caption}}, \code{\link{label}},
+  \code{\link{align}}, \code{\link{digits}}, \code{\link{display}},
+  \code{\link{formatC}}
+}
+
+\examples{
+df <- data.frame(A = c(1.00123, 33.1, 6),
+                 B = c(111111, 3333333, 3123.233))
+## The following code gives the error
+## formal argument "digits" matched by multiple actual arguments
+## print(xtable(df, display = c("s","e","e")),
+##       format.args = list(digits = 3, big.mark = " ", decimal.mark = ","))
+## specify digits as argument to xtable instead
+print(xtable(df, display = c("s","f","f"), digits = 4),
+      format.args = list(big.mark = " ", decimal.mark = ","))
+## The following code gives the error
+## formal argument "format" matched by multiple actual arguments
+## print(xtable(df, digits = 4),
+##       format.args = list(format = c("s","e","e"),
+##                          big.mark = " ", decimal.mark = ","))
+## specify format using display argument in xtable
+print(xtable(df, display = c("s","e","e"), digits = 4),
+      format.args = list(big.mark = " ", decimal.mark = ","))
+
+}
+
+\keyword{print}
diff --git a/man/string.Rd b/man/string.Rd
new file mode 100644
index 0000000..c117fcf
--- /dev/null
+++ b/man/string.Rd
@@ -0,0 +1,30 @@
+\name{string}
+\alias{string}
+\alias{print.string}
+\alias{is.string}
+\alias{as.string}
+\alias{+.string}
+\title{String handling functions}
+\description{Private functions for conveniently working with strings.}
+\usage{
+  string(text,file="",append=FALSE)
+  \method{print}{string}(x,...)
+  \method{+}{string}(x,y)
+  as.string(x,file="",append=FALSE)
+  is.string(x)
+}
+\arguments{
+  \item{text}{A character object.}
+  \item{file}{Name of the file that should receive the printed string.}
+  \item{append}{Should the printed string be appended to the file?}
+  \item{x}{A \code{string} object.}
+  \item{y}{A \code{string} object.}
+  \item{...}{Additional arguments.  (Currently ignored.)}
+}
+\details{
+  These functions are private functions used by \code{print.xtable}.  They are
+  not intended to be used elsewhere.
+}
+\author{David Dahl \email{dahl at stat.byu.edu} with contributions and suggestions from many others (see source code).}
+\seealso{\code{\link{print.xtable}}}
+\keyword{print}
diff --git a/man/table.attributes.Rd b/man/table.attributes.Rd
new file mode 100644
index 0000000..d9da8a7
--- /dev/null
+++ b/man/table.attributes.Rd
@@ -0,0 +1,47 @@
+\name{table.attributes}
+\alias{caption}
+\alias{caption.xtable}
+\alias{caption<-}
+\alias{caption<-.xtable}
+\alias{label}
+\alias{label.xtable}
+\alias{label<-}
+\alias{label<-.xtable}
+\alias{align}
+\alias{align.xtable}
+\alias{align<-}
+\alias{align<-.xtable}
+\alias{digits}
+\alias{digits.xtable}
+\alias{digits<-}
+\alias{digits<-.xtable}
+\alias{display}
+\alias{display.xtable}
+\alias{display<-}
+\alias{display<-.xtable}
+\title{Retrieve and Set Options for Export Tables}
+\description{Functions retrieving or setting table attributes for the supplied object of class \code{"xtable"}.}
+\usage{
+  caption(x,...)
+  caption(x) <- value
+  label(x,...)
+  label(x) <- value
+  align(x,...)
+  align(x) <- value
+  digits(x,...)
+  digits(x) <- value
+  display(x,...)
+  display(x) <- value
+}
+\arguments{
+  \item{x}{An \code{"xtable"} object.}
+  \item{value}{The value of the corresponding attribute.}
+  \item{...}{Additional arguments.  (Currently ignored.)}
+}
+\details{
+  These functions retrieve or set table attributes of the object \code{x} of class \code{"xtable"}.  See
+  \code{xtable} for a description of the options.
+}
+\author{David Dahl \email{dahl at stat.byu.edu} with contributions and suggestions from many others (see source code).}
+\seealso{\code{\link{xtable}}, \code{\link{print.xtable}}, \code{\link{formatC}}}
+\keyword{print}
diff --git a/man/tli.Rd b/man/tli.Rd
new file mode 100644
index 0000000..f6c2b43
--- /dev/null
+++ b/man/tli.Rd
@@ -0,0 +1,20 @@
+\name{tli}
+\alias{tli}
+\title{Math scores from Texas Assessment of Academic Skills (TAAS)}
+\description{
+This data set contains math scores and demographic data of
+100 randomly selected students participating in the Texas
+Assessment of Academic Skills (TAAS).
+}
+\usage{data(tli)}
+\format{A data.frame containing 100 observations with the following columns:
+        \describe{
+          \item{\code{grade}}{Year in school of student}
+          \item{\code{sex}}{Gender of student}
+          \item{\code{disadvg}}{Is the student economically disadvantaged?}
+          \item{\code{ethnicty}}{Race of student}
+          \item{\code{tlimth}}{Math score of student}
+        }
+}
+\source{Texas Education Agency, \url{http://www.tea.state.tx.us}}
+\keyword{datasets}
diff --git a/man/toLatex.Rd b/man/toLatex.Rd
new file mode 100644
index 0000000..bdf6c59
--- /dev/null
+++ b/man/toLatex.Rd
@@ -0,0 +1,26 @@
+\name{toLatex.xtable}
+\alias{toLatex.xtable}
+\title{Convert Table to Latex}
+\description{
+  Function creating a LaTeX representation of an object of class
+  \code{xtable}.
+}
+\usage{
+\method{toLatex}{xtable}(object, ...)
+}
+\arguments{
+  \item{object}{An object of class \code{"xtable"}.}
+  \item{...}{Other arguments to \code{print.xtable}.}  
+}
+\details{
+  This function creates a LaTeX representation of an object of class
+  \code{"xtable"}.  This is a method for the generic \code{"toLatex"} in
+  the core R package \code{"utils"}.
+}
+\author{
+  Charles Roosen \email{roosen at gmail.com} with contributions and
+  suggestions from many others (see source code).
+}
+\seealso{\code{\link{print.xtable}}}
+
+\keyword{toLatex}
diff --git a/man/xtable.Rd b/man/xtable.Rd
new file mode 100644
index 0000000..005382c
--- /dev/null
+++ b/man/xtable.Rd
@@ -0,0 +1,384 @@
+\name{xtable}
+\alias{xtable}
+\alias{xtable.anova}
+\alias{xtable.aov}
+\alias{xtable.aovlist}
+\alias{xtable.data.frame}
+\alias{xtable.glm}
+\alias{xtable.lm}
+\alias{xtable.matrix}
+\alias{xtable.prcomp}
+\alias{xtable.coxph}
+\alias{xtable.summary.aov}
+\alias{xtable.summary.aovlist}
+\alias{xtable.summary.glm}
+\alias{xtable.summary.lm}
+\alias{xtable.summary.prcomp}
+\alias{xtable.ts}
+\alias{xtable.table}
+\alias{xtable.zoo}
+\title{Create Export Tables}
+\description{
+  Function converting an R object to an \code{xtable} object, which can
+  then be printed as a LaTeX or HTML table.
+}
+\usage{
+xtable(x, caption = NULL, label = NULL, align = NULL, digits = NULL,
+       display = NULL, ...)
+}
+\arguments{
+  \item{x}{An R object of class found among \code{methods(xtable)}.  See
+    below on how to write additional method functions for \code{xtable}.}
+  \item{caption}{Character vector of length 1 or 2 containing the
+    table's caption or title.  If length 2, the second item is the
+    "short caption" used when LaTeX generates a "List of Tables". Set to
+    \code{NULL} to suppress the caption.  Default value is \code{NULL}. }
+  \item{label}{Character vector of length 1 containing the LaTeX label
+    or HTML anchor. Set to \code{NULL} to suppress the label.  Default
+    value is \code{NULL}. }
+  \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. Since the row
+    names are printed in the first column, the length of \code{align} is
+    one greater than \code{ncol(x)} if \code{x} is a
+    \code{data.frame}. 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. Default depends on the class of
+    \code{x}. }
+  \item{digits}{
+    Numeric vector of length equal to one (in which case it will be
+    replicated as necessary) or to the number of columns of the
+    resulting table \bold{or} matrix of the same size as the resulting
+    table indicating the number of digits to display in the
+    corresponding columns. Since the row names are printed in the first
+    column, the length of the vector \code{digits} or the number of
+    columns of the matrix \code{digits} is one greater than
+    \code{ncol(x)} if \code{x} is a \code{data.frame}. Default depends
+    of class of \code{x}. If values of \code{digits} are negative, the
+    corresponding values of \code{x} 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.
+    Since the row names are printed in the first column, the length of
+    \code{display} is one greater than \code{ncol(x)} if \code{x} is a
+    \code{data.frame}.  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.  Default depends on the
+    class of \code{x}.}
+  \item{...}{Additional arguments.  (Currently ignored.)}
+}
+\details{
+
+  This function extracts tabular information from \code{x} and returns
+  an object of class \code{"xtable"}.  The nature of the table generated
+  depends on the class of \code{x}.  For example, \code{aov} objects
+  produce ANOVA tables while \code{data.frame} objects produce a table
+  of the entire data.frame.  One can optionally provide a caption
+  (called a title in HTML) or label (called an anchor in HTML), as well
+  as formatting specifications.  Default values for \code{align},
+  \code{digits}, and \code{display} are class dependent.
+
+  The available method functions for \code{xtable} are given by
+  \code{methods(xtable)}.  Users can extend the list of available
+  classes by writing methods for the generic function \code{xtable}.
+  These methods functions should have \code{x} as their first argument
+  with additional arguments to specify \code{caption}, \code{label},
+  \code{align}, \code{digits}, and \code{display}.  Optionally, other
+  arguments may be present to specify how the object \code{x} should be
+  manipulated.  All method functions should return an object whose class
+  if given by \code{c("xtable","data.frame")}.  The resulting object can
+  have attributes \code{caption} and \code{label}, but must have
+  attributes \code{align}, \code{digits}, and \code{display}.  It is
+  strongly recommened that you set these attributes through the provided
+  replacement functions as they perform validity checks.
+  }
+  \value{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 at stat.byu.edu} with contributions and
+  suggestions from many others (see source code).
+}
+\seealso{\code{\link{print.xtable}}, \code{\link{caption}},
+  \code{\link{label}}, \code{\link{align}}, \code{\link{digits}},
+  \code{\link{display}}, \code{\link{formatC}}, \code{\link{methods}}
+}
+\examples{
+
+## Load example dataset
+data(tli)
+
+## Demonstrate data.frame
+tli.table <- xtable(tli[1:20, ])
+digits(tli.table)[c(2, 6)] <- 0
+print(tli.table)
+print(tli.table, type = "html")
+
+## Demonstrate data.frame with different digits in cells
+tli.table <- xtable(tli[1:20, ])
+digits(tli.table) <- matrix( 0:4, nrow = 20, ncol = ncol(tli)+1 )
+print(tli.table)
+print(tli.table, type = "html")
+
+## Demonstrate matrix
+design.matrix <- model.matrix(~ sex*grade, data = tli[1:20, ])
+design.table <- xtable(design.matrix)
+print(design.table)
+print(design.table, type = "html")
+
+## Demonstrate aov
+fm1 <- aov(tlimth ~ sex + ethnicty + grade + disadvg, data = tli)
+fm1.table <- xtable(fm1)
+print(fm1.table)
+print(fm1.table, type = "html")
+
+## Demonstrate lm
+fm2 <- lm(tlimth ~ sex*ethnicty, data = tli)
+fm2.table <- xtable(fm2)
+print(fm2.table)
+print(fm2.table, type = "html")
+print(xtable(anova(fm2)))
+print(xtable(anova(fm2)), type = "html")
+fm2b <- lm(tlimth ~ ethnicty, data = tli)
+print(xtable(anova(fm2b, fm2)))
+print(xtable(anova(fm2b, fm2)), type = "html")
+
+## Demonstrate glm
+fm3 <- glm(disadvg ~ ethnicty*grade, data = tli, family = binomial())
+fm3.table <- xtable(fm3)
+print(fm3.table)
+print(fm3.table, type = "html")
+print(xtable(anova(fm3)))
+print(xtable(anova(fm3)), type = "html")
+
+## Demonstrate aov
+## Taken from help(aov) in R 1.1.1
+## From Venables and Ripley (1997) p.210.
+N <- c(0,1,0,1,1,1,0,0,0,1,1,0,1,1,0,0,1,0,1,0,1,1,0,0)
+P <- c(1,1,0,0,0,1,0,1,1,1,0,0,0,1,0,1,1,0,0,1,0,1,1,0)
+K <- c(1,0,0,1,0,1,1,0,0,1,0,1,0,1,1,0,0,0,1,1,1,0,1,0)
+yield <- c(49.5,62.8,46.8,57.0,59.8,58.5,55.5,56.0,62.8,55.8,69.5,55.0,
+           62.0,48.8,45.5,44.2,52.0,51.5,49.8,48.8,57.2,59.0,53.2,56.0)
+npk <- data.frame(block = gl(6,4), N = factor(N), P = factor(P),
+                  K = factor(K), yield = yield)
+npk.aov <- aov(yield ~ block + N*P*K, npk)
+op <- options(contrasts = c("contr.helmert", "contr.treatment"))
+npk.aovE <- aov(yield ~  N*P*K + Error(block), npk)
+options(op)
+
+summary(npk.aov)
+print(xtable(npk.aov))
+print(xtable(anova(npk.aov)))
+print(xtable(summary(npk.aov)))
+
+summary(npk.aovE)
+print(xtable(npk.aovE), type = "html")
+print(xtable(summary(npk.aovE)), type = "html")
+
+## Demonstrate lm
+## Taken from help(lm) in R 1.1.1
+## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
+## Page 9: Plant Weight Data.
+ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
+trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
+group <- gl(2,10,20, labels = c("Ctl","Trt"))
+weight <- c(ctl, trt)
+lm.D9 <- lm(weight ~ group)
+print(xtable(lm.D9))
+print(xtable(anova(lm.D9)))
+
+## Demonstrate glm
+## Taken from help(glm) in R 1.1.1
+## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
+## Page 93: Randomized Controlled Trial :
+counts <- c(18,17,15,20,10,20,25,13,12)
+outcome <- gl(3,1,9)
+treatment <- gl(3,3)
+d.AD <- data.frame(treatment, outcome, counts)
+glm.D93 <- glm(counts ~ outcome + treatment, family = poisson())
+print(xtable(glm.D93, align = "r|llrc"))
+print(xtable(anova(glm.D93)), hline.after = c(1), size = "small")
+
+## Demonstration of additional formatC() arguments.
+print(fm1.table, format.args = list(big.mark = "'", decimal.mark = ","))
+
+## Demonstration of "short caption" support.
+fm1sc <- aov(tlimth ~ sex + ethnicty + grade, data = tli)
+fm1sc.table <- xtable(fm1sc,
+  caption = c("ANOVA Model with Predictors Sex, Ethnicity, and Grade",
+    "ANOVA: Sex, Ethnicity, Grade"))
+print(fm1sc.table)
+
+## Demonstration of longtable support.
+## Remember to insert \usepackage{longtable} on your LaTeX preamble
+x <- matrix(rnorm(1000), ncol = 10)
+x.big <- xtable(x, label = 'tabbig',
+                caption = 'Example of longtable spanning several pages')
+print(x.big, tabular.environment = 'longtable', floating = FALSE)
+x <- x[1:30, ]
+x.small <- xtable(x, label = 'tabsmall', caption = 'regular table env')
+print(x.small)  # default, no longtable
+
+## Demonstration of sidewaystable support.
+## Remember to insert \usepackage{rotating} on your LaTeX preamble
+print(x.small, floating.environment = 'sidewaystable')
+
+if(require(stats, quietly = TRUE)) {
+  ## Demonstrate prcomp
+  ## Taken from help(prcomp) in mva package of R 1.1.1
+  data(USArrests)
+  pr1 <- prcomp(USArrests)
+  print(xtable(pr1))
+  print(xtable(summary(pr1)))
+
+#  ## Demonstrate princomp
+#  ## Taken from help(princomp) in mva package of R 1.1.1
+#  pr2 <- princomp(USArrests)
+#  print(xtable(pr2))
+}
+
+## Demonstrate include.rownames, include.colnames,
+## only.contents and add.to.row arguments
+set.seed(2345)
+res <- matrix(sample(0:9, size = 6*9, replace = TRUE), ncol = 6, nrow = 9)
+xres <- xtable(res)
+digits(xres) <- rep(0, 7)
+addtorow <- list()
+addtorow$pos <- list()
+addtorow$pos[[1]] <- c(0, 2)
+addtorow$pos[[2]] <- 4
+addtorow$command <- c('\\vspace{2mm} \n', '\\vspace{10mm} \n')
+print(xres, add.to.row = addtorow, include.rownames = FALSE,
+      include.colnames = TRUE, only.contents = TRUE,
+      hline.after = c(0, 0, 9, 9))
+
+## Demonstrate include.rownames, include.colnames,
+## only.contents and add.to.row arguments in Rweave files
+
+\dontrun{
+ \begin{small}
+ \setlongtables % For longtable version 3.x or less
+ \begin{longtable}{
+ <<results = tex, fig = FALSE>>=
+ cat(paste(c('c', rep('cc', 34/2-1), 'c'), collapse = '@{\\hspace{2pt}}'))
+ @
+ }
+ \hline
+ \endhead
+ \hline
+ \endfoot
+ <<results = tex, fig = FALSE>>=
+ library(xtable)
+ set.seed(2345)
+ res <- matrix(sample(0:9, size = 34*90, replace = TRUE), ncol = 34, nrow = 90)
+ xres <- xtable(res)
+ digits(xres) <- rep(0, 35)
+ addtorow <- list()
+ addtorow$pos <- list()
+ addtorow$pos[[1]] <- c(seq(4, 40, 5), seq(49, 85, 5))
+ addtorow$pos[[2]] <- 45
+ addtorow$command <- c('\\vspace{2mm} \n', '\\newpage \n')
+ print(xres, add.to.row = addtorow, include.rownames = FALSE,
+       include.colnames = FALSE, only.contents = TRUE, hline.after = NULL)
+ @
+ \end{longtable}
+ \end{small}
+}
+
+## Demonstrate sanitization
+mat <- round(matrix(c(0.9, 0.89, 200, 0.045, 2.0), c(1, 5)), 4)
+rownames(mat) <- "$y_{t-1}$"
+colnames(mat) <- c("$R^2$", "$\\\bar{R}^2$", "F-stat", "S.E.E", "DW")
+print(xtable(mat), type = "latex", sanitize.text.function = function(x){x})
+
+## Demonstrate booktabs
+print(tli.table)
+print(tli.table, hline.after = c(-1,0))
+print(tli.table, hline.after = NULL)
+print(tli.table,
+      add.to.row = list(pos = list(2), command = c("\\vspace{2mm} \n")))
+
+print(tli.table, booktabs = TRUE)
+print(tli.table, booktabs = TRUE, hline.after = c(-1,0))
+print(tli.table, booktabs = TRUE, hline.after = NULL)
+print(tli.table, booktabs = TRUE,
+  add.to.row = list(pos = list(2), command = c("\\vspace{2mm} \n")))
+print(tli.table, booktabs = TRUE, add.to.row = list(pos = list(2),
+  command = c("youhou\n")), tabular.environment = "longtable")
+
+\testonly{
+  for(i in c("latex","html")) {
+    outFileName <- paste("xtable.", ifelse(i=="latex", "tex", i), sep = "")
+    print(tli.table, type = i, file = outFileName, append = FALSE)
+    print(design.table, type = i, file = outFileName, append = TRUE)
+    print(fm1.table, type = i, file = outFileName, append = TRUE)
+    print(fm2.table, type = i, file = outFileName, append = TRUE)
+    print(fm2.table, type = i, file = outFileName, append = TRUE,
+          math.style.negative = TRUE)
+    print(xtable(anova(fm2)), type = i, file = outFileName, append = TRUE)
+    print(xtable(anova(fm2b, fm2)), type = i, file = outFileName, append = TRUE)
+    print(fm3.table, type = i, file = outFileName, append = TRUE)
+    print(xtable(anova(fm3)), type = i, file = outFileName, append = TRUE)
+    print(xtable(npk.aov), type = i, file = outFileName, append = TRUE)
+    print(xtable(anova(npk.aov)), type = i, file = outFileName, append = TRUE)
+    print(xtable(summary(npk.aov)), type = i, file = outFileName, append = TRUE)
+    print(xtable(npk.aovE), type = i, file = outFileName, append = TRUE)
+    print(xtable(summary(npk.aovE)),
+          type = i, file = outFileName, append = TRUE)
+    if(i=="latex") cat("\\\clearpage\n", file = outFileName, append = TRUE)
+    print(xtable(lm.D9),
+          type = i, file = outFileName, append = TRUE, latex.environment = NULL)
+    print(xtable(lm.D9),
+          type = i, file = outFileName, append = TRUE, latex.environment = "")
+    print(xtable(lm.D9),
+          type = i, file = outFileName, append = TRUE,
+          latex.environment = "center")
+    print(xtable(anova(lm.D9)), type = i, file = outFileName, append = TRUE)
+    print(xtable(glm.D93), type = i, file = outFileName, append = TRUE)
+    print(xtable(anova(glm.D93, test = "Chisq")),
+          type = i, file = outFileName, append = TRUE)
+    print(xtable(glm.D93, align = "r|llrc"),
+          include.rownames = FALSE, include.colnames = TRUE,
+          type = i, file = outFileName, append = TRUE)
+    print(xtable(glm.D93, align = "r||llrc"),
+          include.rownames = TRUE, include.colnames = FALSE,
+          type = i, file = outFileName, append = TRUE)
+    print(xtable(glm.D93, align = "|r||llrc"),
+          include.rownames = FALSE, include.colnames = FALSE,
+          type = i, file = outFileName, append = TRUE)
+    print(xtable(glm.D93, align = "|r||llrc|"),
+          type = i, file = outFileName, append = TRUE)
+    print(xtable(anova(glm.D93)),
+          hline.after = c(1), size = "small",
+          type = i, file = outFileName, append = TRUE)
+    if(require(stats, quietly = TRUE)) {
+      print(xtable(pr1), type = i, file = outFileName, append = TRUE)
+      print(xtable(summary(pr1)), type = i, file = outFileName, append = TRUE)
+      # print(xtable(pr2), type = i, file = outFileName, append = TRUE)
+    }
+    temp.table <- xtable(ts(cumsum(1+round(rnorm(100), 2)),
+                            start = c(1954, 7), frequency = 12))
+    caption(temp.table) <- "Time series example"
+    print(temp.table, type = i, file = outFileName,
+          append = TRUE, caption.placement = "top", table.placement = "h")
+    print(temp.table, type = i, file = outFileName,
+          append = TRUE, caption.placement = "bottom", table.placement = "htb")
+  }
+}
+
+}
+\keyword{file}
diff --git a/tests/test.margintable.R b/tests/test.margintable.R
new file mode 100644
index 0000000..8311558
--- /dev/null
+++ b/tests/test.margintable.R
@@ -0,0 +1,47 @@
+### Test of feature request #2168 implementation
+### Enables use of margintable floating environment
+### DJS, 17/08/2012
+library(xtable)
+x <- matrix(rnorm(6), ncol = 2)
+x.small <- xtable(x, label='tabsmall', caption = 'A margin table')
+print(x.small, floating.environment = 'margintable',
+      table.environments = "",
+      table.placement = NULL)
+## % latex table generated in R 2.15.0 by xtable 1.7-1 package
+## % Fri Aug 17 01:42:42 2012
+## \begin{margintable}
+## \centering
+## \begin{tabular}{rrr}
+##   \hline
+##  & 1 & 2 \\
+##   \hline
+## 1 & 1.42 & -1.11 \\
+##   2 & -0.57 & 0.23 \\
+##   3 & -0.67 & -0.60 \\
+##    \hline
+## \end{tabular}
+## \caption{A margin table}
+## \label{tabsmall}
+## \end{margintable}
+print(x.small, floating.environment = 'margintable',
+      table.environments = "")
+## % latex table generated in R 2.15.0 by xtable 1.7-1 package
+## % Fri Aug 17 01:42:46 2012
+## \begin{margintable}
+## \centering
+## \begin{tabular}{rrr}
+##   \hline
+##  & 1 & 2 \\
+##   \hline
+## 1 & 1.42 & -1.11 \\
+##   2 & -0.57 & 0.23 \\
+##   3 & -0.67 & -0.60 \\
+##    \hline
+## \end{tabular}
+## \caption{A margin table}
+## \label{tabsmall}
+## \end{margintable}
+## Warning message:
+## In print.xtable(x.small, floating.environment = "margintable", table.environments = "") :
+##   margintable does not allow for table placement; setting table.placement to NULL
+
diff --git a/tests/test.xtable.R b/tests/test.xtable.R
new file mode 100644
index 0000000..6f62cab
--- /dev/null
+++ b/tests/test.xtable.R
@@ -0,0 +1,27 @@
+### Test of implementation of request #2104
+### Use of \centering rather that center environment when centering tables
+### DJS, 16/8/2012
+require(xtable)
+ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
+trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
+group <- gl(2,10,20, labels=c("Ctl","Trt"))
+weight <- c(ctl, trt)
+lm.D9 <- lm(weight ~ group)
+class(lm.D9)
+
+xtable(lm.D9, caption="\\tt latex.environment=\"center\"")
+
+## % latex table generated in R 2.15.0 by xtable 1.7-1 package
+## % Thu Aug 16 15:44:09 2012
+## \begin{table}[ht]
+## \centering
+## \begin{tabular}{rrrrr}
+##   \hline
+##  & Estimate & Std. Error & t value & Pr($>$$|$t$|$) \\
+##   \hline
+## (Intercept) & 5.0320 & 0.2202 & 22.85 & 0.0000 \\
+##   groupTrt & -0.3710 & 0.3114 & -1.19 & 0.2490 \\
+##    \hline
+## \end{tabular}
+## \caption{\tt latex.environment="center"}
+## \end{table}
diff --git a/tests/test.xtable.data.frame.R b/tests/test.xtable.data.frame.R
new file mode 100644
index 0000000..5abd95d
--- /dev/null
+++ b/tests/test.xtable.data.frame.R
@@ -0,0 +1,23 @@
+### Test code for logicals bug (number 1911)
+### David Scott, <d.scott at auckland.ac.nz>, 2012-08-10
+### Example of problem with logical
+library(xtable)
+mydf <- data.frame(x = c(1,2), y = c(TRUE,FALSE))
+xtable(mydf)
+
+### Output should be
+## % latex table generated in R 2.15.0 by xtable 1.7-0 package
+## % Fri Aug 10 23:16:30 2012
+## \begin{table}[ht]
+## \begin{center}
+## \begin{tabular}{rrl}
+##   \hline
+##  & x & y \\
+##   \hline
+## 1 & 1.00 & TRUE \\
+##   2 & 2.00 & FALSE \\
+##    \hline
+## \end{tabular}
+## \end{center}
+## \end{table}
+
diff --git a/vignettes/margintable.Rnw b/vignettes/margintable.Rnw
new file mode 100644
index 0000000..b12c583
--- /dev/null
+++ b/vignettes/margintable.Rnw
@@ -0,0 +1,64 @@
+%\VignetteIndexEntry{xtable margintable}
+%\VignetteKeywords{LaTeX, HTML, table, margintable}
+
+
+\documentclass{tufte-handout}
+
+
+\title{
+A Margin Table Example
+}
+\author{David J. Scott}
+
+\usepackage{Sweave}
+\SweaveOpts{prefix.string=figdir/fig,debug=TRUE,eps=FALSE,echo=TRUE}
+\usepackage{rotating}
+\usepackage{longtable}
+\usepackage{booktabs}
+\usepackage{tabularx}
+\usepackage{hyperref}
+\usepackage{fancyvrb}
+\fvset{fontsize=\normalsize}
+
+\begin{document}
+
+\section{The Example}
+\label{sec:example}
+
+This document uses the Tufte handout \LaTeX\ document style. This is
+specified by the use of the document class as
+\Verb|\documentclass{tufte-handout}|.
+
+The Tufte-\LaTeX\ document classes define a style similar to the
+style Edward Tufte uses in his books and handouts.  Tufte's style is known
+for its extensive use of sidenotes, tight integration of graphics with
+text, and well-set typography.
+
+One of the most prominent and distinctive features of this style is the
+extensive use of sidenotes.  There is a wide margin to provide ample room
+for sidenotes and small figures.  Any \Verb|\footnote|s will automatically
+be converted to sidenotes.
+
+Here is an example of a margin table, suggested by Felix Sch\"onbrodt
+\Verb|<nicebread at gmx.net>|. I am not sure about its usefullness in
+practice however. Note that \Verb|latex.environments = ""| avoids the
+default option of tables being centered, which in this example would
+lead to the caption not being directly under the table. Most
+importantly, \Verb|table.placement = NULL| is required to ensure that
+the default table placement options \Verb|[ht]| being inserted after
+\Verb|\begin{margintable}|. This is necessary because the margintable
+  environment does not allow placement options like \Verb|[ht]|.
+
+<<>>=
+library(xtable)
+x <- matrix(rnorm(6), ncol = 2)
+x.small <- xtable(x, label = 'tabsmall', caption = 'A margin table')
+@
+
+<<results=tex>>=
+print(x.small,floating.environment='margintable',
+      latex.environments = "",
+      table.placement = NULL)
+@
+
+\end{document}
diff --git a/vignettes/xtableGallery.snw b/vignettes/xtableGallery.snw
new file mode 100644
index 0000000..2dfa32b
--- /dev/null
+++ b/vignettes/xtableGallery.snw
@@ -0,0 +1,585 @@
+%\VignetteIndexEntry{xtable Gallery}
+%\VignetteDepends{xtable}
+%\VignetteKeywords{LaTeX,HTML,table}
+%\VignettePackage{xtable}
+
+%**************************************************************************
+%
+% # $Id:$
+
+% $Revision:  $
+% $Author: $
+% $Date:  $
+
+<<echo=FALSE,eval=FALSE>>=
+makeme <- function() {
+	# I am a convenience function for debugging and can be ignored
+	setwd("C:/JonathanSwinton/PathwayModeling/src/R/SourcePackages/xtable/inst/doc")
+	Sweave("xtableGallery.RnW",stylepath=FALSE)
+}
+makeme()
+@
+
+\documentclass[letterpaper]{article}
+
+\title{
+The xtable gallery
+}
+\author{Jonathan Swinton <jonathan at swintons.net>\\ with small contributions from others}
+
+\usepackage{Sweave}
+\SweaveOpts{prefix.string=figdir/fig,debug=TRUE,eps=FALSE,echo=TRUE}
+\usepackage{rotating}
+\usepackage{longtable}
+\usepackage{booktabs}
+\usepackage{tabularx}
+%\usepackage{hyperref}
+\begin{document}
+
+\maketitle
+\section{Summary}
+This document gives a gallery of tables which can be made
+by using the {\tt xtable} package to create \LaTeX\ output.
+It doubles as a regression check for the package.
+
+<<>>=
+library(xtable)
+@
+
+\section{Gallery}
+\subsection{Data frame}
+Load example dataset
+<<>>=
+data(tli)
+
+## Demonstrate data.frame
+tli.table <- xtable(tli[1:10,])
+digits(tli.table)[c(2,6)] <- 0
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE)
+@
+
+\subsection{Matrix}
+<<>>=
+design.matrix <- model.matrix(~ sex*grade, data=tli[1:10,])
+design.table <- xtable(design.matrix)
+@
+<<results=tex>>=
+print(design.table,floating=FALSE)
+@
+
+\subsection{aov}
+<<>>=
+fm1 <- aov(tlimth ~ sex + ethnicty + grade + disadvg, data=tli)
+fm1.table <- xtable(fm1)
+@
+<<results=tex>>=
+print(fm1.table,floating=FALSE)
+@
+\subsection{lm}
+<<>>=
+fm2 <- lm(tlimth ~ sex*ethnicty, data=tli)
+fm2.table <- xtable(fm2)
+@
+<<results=tex>>=
+print(fm2.table,floating=FALSE)
+@
+\subsubsection{anova object}
+
+<<results=tex>>=
+print(xtable(anova(fm2)),floating=FALSE)
+@
+\subsubsection{Another anova object}
+<<>>=
+fm2b <- lm(tlimth ~ ethnicty, data=tli)
+@
+<<results=tex>>=
+print(xtable(anova(fm2b,fm2)),floating=FALSE)
+@
+
+
+\subsection{glm}
+
+<<>>=
+
+## Demonstrate glm
+fm3 <- glm(disadvg ~ ethnicty*grade, data=tli, family=binomial())
+fm3.table <- xtable(fm3)
+@
+<<results=tex>>=
+print(fm3.table,floating=FALSE)
+@
+
+\subsubsection{anova object}
+@
+<<results=tex>>=
+print(xtable(anova(fm3)),floating=FALSE)
+@
+
+
+\subsection{More aov}
+<<>>=
+
+## Demonstrate aov
+## Taken from help(aov) in R 1.1.1
+## From Venables and Ripley (1997) p.210.
+N <- c(0,1,0,1,1,1,0,0,0,1,1,0,1,1,0,0,1,0,1,0,1,1,0,0)
+P <- c(1,1,0,0,0,1,0,1,1,1,0,0,0,1,0,1,1,0,0,1,0,1,1,0)
+K <- c(1,0,0,1,0,1,1,0,0,1,0,1,0,1,1,0,0,0,1,1,1,0,1,0)
+yield <- c(49.5,62.8,46.8,57.0,59.8,58.5,55.5,56.0,62.8,55.8,69.5,55.0,
+           62.0,48.8,45.5,44.2,52.0,51.5,49.8,48.8,57.2,59.0,53.2,56.0)
+npk <- data.frame(block=gl(6,4), N=factor(N), P=factor(P), K=factor(K), yield=yield)
+npk.aov <- aov(yield ~ block + N*P*K, npk)
+op <- options(contrasts=c("contr.helmert", "contr.treatment"))
+npk.aovE <- aov(yield ~  N*P*K + Error(block), npk)
+options(op)
+#summary(npk.aov)
+@
+<<results=tex>>=
+print(xtable(npk.aov),floating=FALSE)
+@
+
+\subsubsection{anova object}
+<<results=tex>>=
+print(xtable(anova(npk.aov)),floating=FALSE)
+@
+
+\subsubsection{Another anova object}
+<<results=tex>>=
+print(xtable(summary(npk.aov)),floating=FALSE)
+@
+
+<<>>=
+#summary(npk.aovE)
+@
+<<results=tex>>=
+print(xtable(npk.aovE),floating=FALSE)
+@
+
+
+<<results=tex>>=
+print(xtable(summary(npk.aovE)),floating=FALSE)
+@
+
+\subsection{More lm}
+<<>>=
+
+## Demonstrate lm
+## Taken from help(lm) in R 1.1.1
+## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
+## Page 9: Plant Weight Data.
+ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
+trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
+group <- gl(2,10,20, labels=c("Ctl","Trt"))
+weight <- c(ctl, trt)
+lm.D9 <- lm(weight ~ group)
+@
+<<results=tex>>=
+print(xtable(lm.D9),floating=FALSE)
+@
+
+
+<<results=tex>>=
+print(xtable(anova(lm.D9)),floating=FALSE)
+@
+
+\subsection{More glm}
+<<>>=
+
+## Demonstrate glm
+## Taken from help(glm) in R 1.1.1
+## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
+## Page 93: Randomized Controlled Trial :
+counts <- c(18,17,15,20,10,20,25,13,12)
+outcome <- gl(3,1,9)
+treatment <- gl(3,3)
+d.AD <- data.frame(treatment, outcome, counts)
+glm.D93 <- glm(counts ~ outcome + treatment, family=poisson())
+@
+<<results=tex>>=
+print(xtable(glm.D93,align="r|llrc"),floating=FALSE)
+@
+
+\subsection{prcomp}
+<<prcomp>>=
+if(require(stats,quietly=TRUE)) {
+  ## Demonstrate prcomp
+  ## Taken from help(prcomp) in mva package of R 1.1.1
+  data(USArrests)
+  pr1 <- prcomp(USArrests)
+}
+@
+<<results=tex>>=
+if(require(stats,quietly=TRUE)) {
+  print(xtable(pr1),floating=FALSE)
+}
+@
+
+
+@
+<<results=tex>>=
+  print(xtable(summary(pr1)),floating=FALSE)
+@
+
+
+
+<<>>=
+#  ## Demonstrate princomp
+#  ## Taken from help(princomp) in mva package of R 1.1.1
+#  pr2 <- princomp(USArrests)
+#  print(xtable(pr2))
+@
+\subsection{Time series}
+
+<<>>=
+temp.ts <- ts(cumsum(1+round(rnorm(100), 0)), start = c(1954, 7), frequency=12)
+   temp.table <- xtable(temp.ts,digits=0)
+    caption(temp.table) <- "Time series example"
+@
+<<results=tex>>=
+    print(temp.table,floating=FALSE)
+@
+<<savetofile,echo=FALSE>>=
+if (FALSE) {
+  for(i in c("latex","html")) {
+    outFileName <- paste("xtable.",ifelse(i=="latex","tex",i),sep="")
+    print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environments=NULL)
+    print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environments="")
+    print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environments="center")
+    print(xtable(anova(glm.D93,test="Chisq")),type=i,file=outFileName,append=TRUE)
+    print(xtable(anova(glm.D93)),hline.after=c(1),size="small",type=i,file=outFileName,append=TRUE)
+      # print(xtable(pr2),type=i,file=outFileName,append=TRUE)
+         }
+}
+@
+
+\section{Sanitization}
+<<>>=
+insane <- data.frame(Name=c("Ampersand","Greater than","Less than","Underscore","Per cent","Dollar","Backslash","Hash", "Caret", "Tilde","Left brace","Right brace"),
+				Character = I(c("&",">",		"<",		"_",		"%",		"$",		"\\", "#",	"^",		"~","{","}")))
+colnames(insane)[2] <- paste(insane[,2],collapse="")
+@
+
+<<pxti,results=tex>>=
+print( xtable(insane))
+@
+Sometimes you might want to have your own sanitization function
+<<>>=
+wanttex <- xtable(data.frame( label=paste("Value_is $10^{-",1:3,"}$",sep="")))
+@
+<<results=tex>>=
+print(wanttex,sanitize.text.function=function(str)gsub("_","\\_",str,fixed=TRUE))
+@
+
+\subsection{Markup in tables}
+
+Markup can be kept in tables, including column and row names, by using a custom sanitize.text.function:
+
+<<>>=
+mat <- round(matrix(c(0.9, 0.89, 200, 0.045, 2.0), c(1, 5)), 4)
+rownames(mat) <- "$y_{t-1}$"
+colnames(mat) <- c("$R^2$", "$\\bar{R}^2$", "F-stat", "S.E.E", "DW")
+mat <- xtable(mat)
+@
+<<results=tex>>=
+print(mat, sanitize.text.function = function(x){x})
+@
+
+% By David Dahl to demonstrate contribution from David Whitting, 2007-10-09.
+You can also have sanitize functions that are specific to column or row names.  In the table below, the row name is not sanitized but column names and table elements are:
+<<>>=
+money <- matrix(c("$1,000","$900","$100"),ncol=3,dimnames=list("$\\alpha$",c("Income (US$)","Expenses (US$)","Profit (US$)")))
+@
+<<results=tex>>=
+print(xtable(money),sanitize.rownames.function=function(x) {x})
+@
+
+\section{Format examples}
+\subsection{Adding a centering environment }
+<<results=tex>>=
+   print(xtable(lm.D9,caption="\\tt latex.environments=NULL"),latex.environments=NULL)
+    print(xtable(lm.D9,caption="\\tt latex.environments=\"\""),latex.environments="")
+    print(xtable(lm.D9,caption="\\tt latex.environments=\"center\""),latex.environments="center")
+@
+\subsection{Column alignment}
+
+<<>>=
+tli.table <- xtable(tli[1:10,])
+@
+<<>>=
+align(tli.table) <- rep("r",6)
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE)
+@
+\subsubsection{Single string and column lines}
+<<>>=
+align(tli.table) <- "|rrl|l|lr|"
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE)
+@
+\subsubsection{Fixed width columns}
+<<>>=
+align(tli.table) <- "|rr|lp{3cm}l|r|"
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE)
+@
+
+\subsection{Significant digits}
+
+
+Specify with a single argument
+<<>>=
+digits(tli.table) <- 3
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE,)
+@
+
+
+or one for each column, counting the row names
+<<>>=
+digits(tli.table) <- 1:(ncol(tli)+1)
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE,)
+@
+
+
+or as a full matrix
+<<>>=
+digits(tli.table) <- matrix( 0:4, nrow = 10, ncol = ncol(tli)+1 )
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE,)
+@
+
+\subsection{Suppress row names}
+<<results=tex>>=
+print((tli.table),include.rownames=FALSE,floating=FALSE)
+@
+
+If you want a vertical line on the left, you need to change the align attribute.
+<<>>=
+align(tli.table) <- "|r|r|lp{3cm}l|r|"
+@
+<<results=tex>>=
+print((tli.table),include.rownames=FALSE,floating=FALSE)
+@
+
+Revert the alignment to what is was before.
+<<>>=
+align(tli.table) <- "|rr|lp{3cm}l|r|"
+@
+
+\subsection{Suppress column names}
+<<results=tex>>=
+print((tli.table),include.colnames=FALSE,floating=FALSE)
+@
+\\
+Note the doubled header lines which can be suppressed with, eg,
+<<results=tex>>=
+print(tli.table,include.colnames=FALSE,floating=FALSE,hline.after=c(0,nrow(tli.table)))
+@
+
+\subsection{Suppress row and column names}
+<<results=tex>>=
+print((tli.table),include.colnames=FALSE,include.rownames=FALSE,floating=FALSE)
+@
+
+\subsection{Rotate row and column names}
+The {\tt rotate.rownames } and {\tt rotate.colnames} arguments can be
+used to rotate the row and/or column names.
+
+<<results=tex>>=
+print((tli.table),rotate.rownames=TRUE,rotate.colnames=TRUE)
+@
+
+\subsection{Horizontal lines}
+
+\subsubsection{Line locations}
+
+Use the {\tt hline.after} argument to specify the position of the horizontal lines.
+
+<<results=tex>>=
+print(xtable(anova(glm.D93)),hline.after=c(1),floating=FALSE)
+@
+
+\subsubsection{Line styles}
+
+The \LaTeX package {\tt booktabs} can be used to specify different
+line style tags for top, middle, and bottom lines.  Specifying
+{\tt booktabs = TRUE} will lead to separate tags being generated
+for the three line types.
+
+Insert \verb|\usepackage{booktabs}| in your \LaTeX preamble and define
+the {\tt toprule}, {\tt midrule}, and {\tt bottomrule} tags to specify
+the line styles. By default, when no value is given for
+\texttt{hline.after}, a \texttt{toprule} will be drawn above the
+table, a \texttt{midrule} after the table headings and a
+\texttt{bottomrule} below the table. The width of the top and bottom
+rules can be set by supplying a value to \verb+\heavyrulewidth+. The
+width of the midrules can be set by supplying a value to
+\verb+\lightrulewidth+. The following tables have
+\verb+\heavyrulewidth = 2pt+ and \verb+\lightrulewidth = 0.5pt+, to
+ensure the difference in weight is noticeable.
+
+There is no support for \verb+\cmidrule+ or \verb+\specialrule+
+although they are part of the \texttt{booktabs} package.
+
+\heavyrulewidth = 2pt
+\lightrulewidth = 0.5pt
+
+<<results=tex>>=
+print(tli.table, booktabs=TRUE, floating = FALSE)
+@
+
+\vspace{12pt}
+If \texttt{hline.after} includes $-1$, a \texttt{toprule} will be
+drawn above the table. If \texttt{hline.after} includes the number of
+rows in the table, a \texttt{bottomrule} will be drawn below the
+table. For any other values specified in \texttt{hline.after}, a
+\texttt{midrule} will be drawn after that line of the table.
+
+The next table has more than one \texttt{midrule}.
+
+<<>>=
+bktbs <- xtable(matrix(1:10, ncol = 2))
+hlines <- c(-1,0,1,nrow(bktbs))
+@
+This command produces the required table.
+<<results=tex>>=
+print(bktbs, booktabs = TRUE, hline.after = hlines, floating = FALSE)
+@
+
+
+\subsection{Table-level \LaTeX}
+<<results=tex>>=
+print(xtable(anova(glm.D93)),size="small",floating=FALSE)
+@
+
+
+\subsection{Long tables}
+Remember to insert \verb|\usepackage{longtable}| in your \LaTeX preamble.
+
+<<longtable>>=
+
+## Demonstration of longtable support.
+x <- matrix(rnorm(1000), ncol = 10)
+x.big <- xtable(x,label='tabbig',
+	caption='Example of longtable spanning several pages')
+@
+<<results=tex>>=
+print(x.big,tabular.environment='longtable',floating=FALSE)
+@
+
+%%
+%% The column name alignment is off in the following example.
+%% It needs some revision before exposing it. - CR, 7/2/2012
+%%
+%
+%\subsubsection{Long tables with the header on each page}
+%
+%The {\tt add.to.row} argument can be used to display the header
+%for a long table on each page, and to add a "continued" footer
+%on all pages except the last page.
+%
+%<<results=tex>>=
+%library(xtable)
+%x<-matrix(rnorm(1000), ncol = 10)
+%addtorow<-list()
+%addtorow$pos<-list()
+%addtorow$pos[[1]]<-c(0)
+%addtorow$command<-c(paste(
+%    "\\hline \n",
+%    "  \\endhead \n",
+%    "  \\hline \n",
+%    "  {\\footnotesize Continued on next page} \n",
+%    "  \\endfoot \n",
+%    "  \\endlastfoot \n",sep=""))
+%x.big2 <- xtable(x, label = "tabbig2",
+%    caption = "Example of longtable with the header on each page")
+%print(x.big2, tabular.environment = "longtable", floating = FALSE,
+%include.rownames=FALSE, add.to.row=addtorow, hline.after=c(-1) )
+%@
+
+\subsection{Sideways tables}
+Remember to insert \verb|\usepackage{rotating}| in your LaTeX preamble.
+Sideways tables can't be forced in place with the `H' specifier, but you can
+use the \verb|\clearpage| command to get them fairly nearby.
+
+<<>>=
+x <- x[1:30,]
+x.small <- xtable(x,label='tabsmall',caption='A sideways table')
+@
+
+<<results=tex>>=
+print(x.small,floating.environment='sidewaystable')
+@
+\clearpage
+
+\subsection{Rescaled tables}
+Specify a {\tt scalebox} value to rescale the table.
+
+<<>>=
+x <- x[1:20,]
+x.rescale <- xtable(x,label='tabrescaled',caption='A rescaled table')
+@
+
+<<results=tex>>=
+print(x.rescale, scalebox=0.7)
+@
+
+\subsection{Table Width}
+The {\tt tabularx} tabular environment provides more alignment options,
+and has a {\tt width} argument to specify the table width.
+
+Remember to insert \verb|\usepackage{tabularx}| in your \LaTeX preamble.
+
+<<>>=
+df.width <- data.frame(
+  "label 1 with much more text than is needed" = c("item 1", "A"),
+  "label 2 is also very long" = c("item 2","B"),
+  "label 3" = c("item 3","C"),
+  "label 4" = c("item 4 but again with too much text","D"),
+  check.names = FALSE)
+
+x.width <- xtable(df.width,
+  caption="Using the 'tabularx' environment")
+align(x.width) <- "|l|X|X|l|X|"
+@
+
+<<results=tex>>=
+print(x.width, tabular.environment="tabularx",
+  width="\\textwidth")
+@
+
+\section{Suppressing Printing}
+By default the {\tt print} method will print the LaTeX or HTML to standard
+output and also return the character strings invisibly.  The printing to
+standard output can be suppressed by specifying {\tt print.results = FALSE}.
+
+<<>>=
+x.out <- print(tli.table, print.results = FALSE)
+@
+
+Formatted output can also be captured without printing with the
+{\tt toLatex} method.  This function returns an object of class
+{\tt "Latex"}.
+
+<<>>=
+x.ltx <- toLatex(tli.table)
+class(x.ltx)
+x.ltx
+@
+
+\section{Acknowledgements}
+Most of the examples in this gallery are taken from the {\tt xtable} documentation.
+\section{R Session information}
+<<results=tex>>=
+toLatex(sessionInfo())
+@
+\end{document}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/r-cran-xtable.git



More information about the debian-science-commits mailing list