]> git.donarmstrong.com Git - xtable.git/commitdiff
xtable Version 1.5-6 (2009-11-08) downloaded from CRAN on 2011-10-04.
authorroosen <roosen@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Tue, 4 Oct 2011 15:44:18 +0000 (15:44 +0000)
committerroosen <roosen@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Tue, 4 Oct 2011 15:44:18 +0000 (15:44 +0000)
git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@2 edb9625f-4e0d-4859-8d74-9fd3b1da38cb

14 files changed:
pkg/DESCRIPTION [new file with mode: 0644]
pkg/NAMESPACE [new file with mode: 0644]
pkg/NEWS [new file with mode: 0644]
pkg/R/print.xtable.R [new file with mode: 0644]
pkg/R/table.attributes.R [new file with mode: 0644]
pkg/R/xtable.R [new file with mode: 0644]
pkg/data/tli.txt [new file with mode: 0644]
pkg/inst/doc/xtableGallery.pdf [new file with mode: 0644]
pkg/inst/doc/xtableGallery.snw [new file with mode: 0644]
pkg/man/print.xtable.Rd [new file with mode: 0644]
pkg/man/string.Rd [new file with mode: 0644]
pkg/man/table.attributes.Rd [new file with mode: 0644]
pkg/man/tli.Rd [new file with mode: 0644]
pkg/man/xtable.Rd [new file with mode: 0644]

diff --git a/pkg/DESCRIPTION b/pkg/DESCRIPTION
new file mode 100644 (file)
index 0000000..92c726b
--- /dev/null
@@ -0,0 +1,12 @@
+Package: xtable
+Version: 1.5-6
+Date: 2009/10/30
+Title: Export tables to LaTeX or HTML
+Author: David B. Dahl <dahl@stat.tamu.edu>
+Maintainer: David B. Dahl <dahl@stat.tamu.edu>
+Description: Coerce data to LaTeX and HTML tables
+Depends: R (>= 2.6.0)
+License: GPL (>= 2)
+Packaged: 2009-11-06 22:52:33 UTC; dahl
+Repository: CRAN
+Date/Publication: 2009-11-08 17:53:42
diff --git a/pkg/NAMESPACE b/pkg/NAMESPACE
new file mode 100644 (file)
index 0000000..521cf2d
--- /dev/null
@@ -0,0 +1,35 @@
+# NAMESPACE work by Robert Gentleman <rgentlem@fhcrc.org>
+# in e-mail on July 30, 2007.
+
+export("caption<-", "caption", "label", "label<-",
+   "align<-", "align", "digits<-", "digits", "display<-",
+   "display", "xtable")
+
+S3method("print", "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/pkg/NEWS b/pkg/NEWS
new file mode 100644 (file)
index 0000000..897a8d8
--- /dev/null
+++ b/pkg/NEWS
@@ -0,0 +1,10 @@
+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/pkg/R/print.xtable.R b/pkg/R/print.xtable.R
new file mode 100644 (file)
index 0000000..84abb53
--- /dev/null
@@ -0,0 +1,432 @@
+### xtable package
+###
+### Produce LaTeX and HTML tables from R objects.
+###
+### Copyright 2000-2007 David B. Dahl <dahl@stat.tamu.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
+print.xtable <- function(
+  x,
+  type="latex",
+  file="",
+  append=FALSE,
+  floating=TRUE,
+  floating.environment="table",
+  table.placement="ht",
+  caption.placement="bottom",
+  latex.environments=c("center"),
+  tabular.environment="tabular",
+  size=NULL,
+  hline.after=c(-1,0,nrow(x)),
+  NA.string="",
+  include.rownames=TRUE,
+  include.colnames=TRUE,
+  only.contents=FALSE,
+  add.to.row=NULL,
+  sanitize.text.function=NULL,
+  sanitize.rownames.function=sanitize.text.function,
+  sanitize.colnames.function=sanitize.text.function,
+  math.style.negative=FALSE,
+  html.table.attributes="border=1",
+  ...) {
+  # Claudio Agostinelli <claudio@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@unive.it> dated 2006-07-28 include.rownames, include.colnames  
+  pos <- 0
+  if (include.rownames) pos <- 1
+  
+  # Claudio Agostinelli <claudio@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@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@unive.it> dated 2006-07-28 add.to.row
+  # Add further commands at the end of rows
+  if (type=="latex") {
+     PHEADER <- "\\hline\n"
+  } else {
+     PHEADER <- ""
+  }
+   
+  lastcol <- rep(" ", nrow(x)+2)
+  if (!is.null(hline.after)) {
+     add.to.row$pos[[npos+1]] <- hline.after
+     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\"}")
+  if (!all(!is.na(match(floating.environment,c("table","sidewaystable"))))) stop("\"type\" must be in {\"table\", \"sidewaystable\"}")
+  if (!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@uic.edu>" dated 5-19-2003 regarding "texfloat"
+    # See e-mail form "Fernando Henrique Ferraz P. da Rosa" <academic@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@drkw.com>" dated 7-09-2003 regarding "suggestion for an amendment of the source"
+      # See e-mail from "Mitchell, David" <David.Mitchell@dotars.gov.au>" dated 2003-07-09 regarding "Additions to R xtable package"
+      # See e-mail from "Garbade, Sven" <Sven.Garbade@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 <- ""
+        for ( i in 1:length(latex.environments) ) {
+          if ( latex.environments[i] == "" ) next
+          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
+    }
+    BTABULAR <- paste("\\begin{",tabular.environment,"}{",
+                      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@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") {
+        BCAPTION <- "\\caption{"
+        ECAPTION <- "} \\\\ \n"
+        if ((!is.null(attr(x,"caption",exact=TRUE))) && (type=="latex")) BTABULAR <- paste(BTABULAR,  BCAPTION, attr(x,"caption",exact=TRUE), ECAPTION, sep="")
+    }
+    # Claudio Agostinelli <claudio@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="")
+    
+    # BSIZE contributed by Benno <puetz@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"
+    BCAPTION <- "\\caption{"
+    ECAPTION <- "}\n"
+    BROW <- ""
+    EROW <- " \\\\ \n"
+    BTH <- ""
+    ETH <- ""
+    STH <- " & "
+    BTD1 <- " & "
+    BTD2 <- ""
+    BTD3 <- ""
+    ETD  <- ""
+    # Based on contribution from Jonathan Swinton <jonathan@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@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@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@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
+      result <- gsub("&","&amp ",result,fixed=TRUE)
+      result <- gsub(">","&gt ",result,fixed=TRUE)
+      result <- gsub("<","&lt ",result,fixed=TRUE)
+      # Kurt Hornik <Kurt.Hornik@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@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@unive.it> dated 2006-07-28 to set automatically the package version
+  result <- result + BCOMMENT + type + " table generated in " +
+            info$language + " " + info$major + "." + info$minor + " by xtable " + packageDescription('xtable')$Version + " package" + ECOMMENT
+  result <- result + BCOMMENT + date() + ECOMMENT
+  # Claudio Agostinelli <claudio@unive.it> dated 2006-07-28 only.contents
+  if (!only.contents) {
+    result <- result + BTABLE
+    result <- result + BENVIRONMENT
+    if ( floating == TRUE ) {
+      if ((!is.null(attr(x,"caption",exact=TRUE))) && (type=="html" || caption.placement=="top")) result <- result + BCAPTION + attr(x,"caption",exact=TRUE) + ECAPTION
+      if (!is.null(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@unive.it> dated 2006-07-28 include.colnames, include.rownames 
+  if (include.colnames) {
+    result <- result + BROW + BTH
+    if (include.rownames) result <- result + STH
+    if (is.null(sanitize.colnames.function)) {                                     # David G. Whiting in e-mail 2007-10-09
+      result <- result + paste(sanitize(names(x)),collapse=STH)
+    } else {
+      result <- result + paste(sanitize.colnames.function(names(x)), collapse=STH) # David G. Whiting in e-mail 2007-10-09
+    }
+    result <- result + ETH + EROW
+  }
+
+  cols <- matrix("",nrow=nrow(x),ncol=ncol(x)+pos)
+  if (include.rownames) {
+    if (is.null(sanitize.rownames.function)) {                                     # David G. Whiting in e-mail 2007-10-09
+      cols[,1] <- sanitize(row.names(x))
+    } else {
+      cols[,1] <- sanitize.rownames.function(row.names(x))                         # David G. Whiting in e-mail 2007-10-09
+    }
+  }
+
+  disp <- function(y) {
+    if (is.factor(y)) {
+      y <- levels(y)[y]
+    }
+    if (is.list(y)) {
+      y <- unlist(y)
+    }
+    return(y)
+  }
+  # Code for letting "digits" be a matrix was provided by Arne Henningsen <ahenningsen@agric-econ.uni-kiel.de> in e-mail dated 2005-06-04.
+  if( !is.matrix( attr( x, "digits",exact=TRUE ) ) ) {
+    # modified Claudio Agostinelli <claudio@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)) {
+    ina <- is.na(x[,i])
+    is.numeric.column <- is.numeric(x[,i])
+    for( j in 1:nrow( cols ) ) {
+      ### modified Claudio Agostinelli <claudio@unive.it> dated 2009-09-14
+      ### add decimal.mark=options()$OutDec
+      cols[j,i+pos] <-
+        formatC( disp( x[j,i] ),
+          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] ), decimal.mark=options()$OutDec)
+    }
+    if ( any(ina) ) cols[ina,i+pos] <- NA.string
+    # Based on contribution from Jonathan Swinton <jonathan@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") {
+      result <- result + PHEADER
+      ## fix 10-27-09 Liviu Andronic (landronimirc@gmail.com) the following 'if' condition is inserted in order to avoid
+      ## that bottom caption interferes with a top caption of a longtable
+      if(caption.placement=="bottom"){
+        if ((!is.null(attr(x,"caption",exact=TRUE))) && (type=="latex")) result <- result + BCAPTION + attr(x,"caption",exact=TRUE) + ECAPTION
+      }
+      if (!is.null(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(attr(x,"caption",exact=TRUE))) && (type=="latex" && caption.placement=="bottom")) result <- result + BCAPTION + attr(x,"caption",exact=TRUE) + 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)
+  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 coerse argument to a string"))
+  if (class(x)=="string")
+    return(x)
+  stop("Cannot coerse argument to a string")
+}
+
+is.string <- function(x) {
+  return(class(x)=="string")
+}
+
diff --git a/pkg/R/table.attributes.R b/pkg/R/table.attributes.R
new file mode 100644 (file)
index 0000000..f2a08c7
--- /dev/null
@@ -0,0 +1,154 @@
+### xtable package
+###
+### Produce LaTeX and HTML tables from R objects.
+###
+### Copyright 2000-2007 David B. Dahl <dahl@stat.tamu.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)>1)
+    stop("\"caption\" must have length 1")
+  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@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","|") 
+  
+  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@mpipsykl.mpg.de> in e-mail dated Wednesday, December 01, 2004
+# Based on contribution from Jonathan Swinton <jonathan@swintons.net> in e-mail dated Wednesday, January 17, 2007
+  # cat("%",value,"\n")
+  if ( (!is.null(value)) && ( is.character(value) ) && ( length(value) == 1 ) && ( nchar(value) > 1 ) ) {
+        value <- .alignStringToVector(value)
+  } # That should have checked we had only lrcp|
+    # but what if the "if statement" is false?
+    # For simplicity, deleting check present in version 1.4-2 and earlier.
+  c.value <- if (any(!is.na(match(value,"|")))) {
+                value[-which(value=='|')]
+             } 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/pkg/R/xtable.R b/pkg/R/xtable.R
new file mode 100644 (file)
index 0000000..ec6a770
--- /dev/null
@@ -0,0 +1,261 @@
+### xtable package
+###
+### Produce LaTeX and HTML tables from R objects.
+###
+### Copyright 2000-2007 David B. Dahl <dahl@stat.tamu.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] <- as.character(x[,logicals])
+  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@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 {
+    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))
+  }
+}
+
+
+## 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@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@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@mayin.org> in e-mail 2006/07/22
+xtable.zoo <- function(x,...) {
+  return(xtable(as.ts(x),...))
+}
+
diff --git a/pkg/data/tli.txt b/pkg/data/tli.txt
new file mode 100644 (file)
index 0000000..b93213c
--- /dev/null
@@ -0,0 +1,101 @@
+  grade   sex    disadvg   ethnicty   tlimth  
+      6   M      YES       HISPANIC       43  
+      7   M      NO        BLACK          88  
+      5   F      YES       HISPANIC       34  
+      3   M      YES       HISPANIC       65  
+      8   M      YES       WHITE          75  
+      5   M      NO        BLACK          74  
+      8   F      YES       HISPANIC       72  
+      4   M      YES       BLACK          79  
+      6   M      NO        WHITE          88  
+      7   M      YES       HISPANIC       87  
+      3   M      NO        WHITE          79  
+      6   F      NO        WHITE          84  
+      8   M      NO        WHITE          90  
+      5   M      NO        WHITE          73  
+      8   F      NO        WHITE          72  
+      6   F      NO        BLACK          82  
+      4   M      NO        WHITE          69  
+      3   F      YES       HISPANIC       17  
+      3   M      NO        HISPANIC       37  
+      5   M      NO        WHITE          70  
+      6   M      NO        WHITE          90  
+      6   F      NO        WHITE          91  
+      5   F      NO        WHITE          50  
+      7   M      NO        WHITE          83  
+      4   F      YES       BLACK          58  
+      4   M      YES       HISPANIC       85  
+      7   F      NO        WHITE          52  
+      5   M      NO        WHITE          86  
+      4   F      YES       BLACK          79  
+      8   M      NO        WHITE          48  
+      4   F      NO        BLACK          63  
+      8   F      YES       WHITE          88  
+      3   F      YES       HISPANIC       76  
+      7   M      NO        WHITE          79  
+      8   M      NO        WHITE          87  
+      6   F      NO        HISPANIC       80  
+      7   F      NO        WHITE          66  
+      4   F      NO        WHITE          68  
+      6   M      NO        WHITE          92  
+      7   F      NO        WHITE          57  
+      8   F      NO        WHITE          57  
+      4   F      NO        WHITE          66  
+      7   F      NO        BLACK          88  
+      8   F      NO        BLACK          59  
+      6   F      NO        WHITE          87  
+      4   M      YES       BLACK          59  
+      7   M      NO        WHITE          88  
+      6   M      NO        HISPANIC       75  
+      5   M      YES       HISPANIC       93  
+      7   M      YES       BLACK          77  
+      3   M      NO        WHITE          85  
+      3   F      NO        WHITE          84  
+      6   M      NO        WHITE          91  
+      6   M      NO        WHITE          80  
+      3   M      YES       BLACK          80  
+      7   F      NO        WHITE          90  
+      7   F      NO        BLACK          85  
+      5   F      YES       HISPANIC       63  
+      4   F      NO        WHITE          91  
+      6   M      NO        BLACK          59  
+      6   M      YES       WHITE          85  
+      7   F      NO        OTHER          92  
+      8   M      NO        HISPANIC       51  
+      6   F      YES       OTHER          87  
+      6   M      NO        WHITE          92  
+      8   F      NO        WHITE          85  
+      8   M      YES       BLACK          47  
+      4   F      NO        WHITE          78  
+      8   M      YES       HISPANIC       86  
+      7   M      NO        WHITE          86  
+      3   F      NO        BLACK          67  
+      3   M      YES       BLACK          64  
+      5   M      YES       HISPANIC       86  
+      5   F      NO        WHITE          80  
+      4   M      YES       BLACK          81  
+      3   M      NO        WHITE          70  
+      8   F      NO        WHITE          82  
+      5   F      NO        WHITE          69  
+      7   F      NO        WHITE          79  
+      3   F      YES       BLACK          67  
+      6   F      NO        WHITE          91  
+      3   F      YES       HISPANIC       91  
+      4   F      YES       HISPANIC       78  
+      5   F      NO        WHITE          86  
+      4   F      NO        WHITE          87  
+      7   F      NO        WHITE          83  
+      5   F      NO        WHITE          93  
+      3   M      YES       BLACK          70  
+      4   M      YES       BLACK          86  
+      6   F      YES       BLACK          87  
+      6   F      NO        WHITE          83  
+      6   F      YES       BLACK          75  
+      6   M      NO        WHITE          88  
+      5   M      NO        WHITE          91  
+      3   M      YES       HISPANIC       89  
+      7   F      NO        WHITE          91  
+      5   F      YES       WHITE          79  
+      7   M      NO        WHITE          83  
+      6   M      YES       HISPANIC       78  
+      6   F      NO        WHITE          84  
diff --git a/pkg/inst/doc/xtableGallery.pdf b/pkg/inst/doc/xtableGallery.pdf
new file mode 100644 (file)
index 0000000..7f062bd
Binary files /dev/null and b/pkg/inst/doc/xtableGallery.pdf differ
diff --git a/pkg/inst/doc/xtableGallery.snw b/pkg/inst/doc/xtableGallery.snw
new file mode 100644 (file)
index 0000000..995db16
--- /dev/null
@@ -0,0 +1,440 @@
+%\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@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{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.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(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.environment=NULL"),latex.environment=NULL)
+    print(xtable(lm.D9,caption="\\tt latex.environment=\"\""),latex.environment="")
+    print(xtable(lm.D9,caption="\\tt latex.environment=\"center\""),latex.environment="center")
+@
+\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{Horizontal lines}
+<<results=tex>>=
+print(xtable(anova(glm.D93)),hline.after=c(1),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.
+See Table \ref{tabbig}.
+
+<<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)
+@
+
+
+\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.
+See Table \ref{tabsmall}.
+
+<<>>=
+x <- x[1:30,]
+x.small <- xtable(x,label='tabsmall',caption='A sideways table')
+@
+
+<<results=tex>>=
+print(x.small,floating.environment='sidewaystable')
+@
+\clearpage
+
+\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/pkg/man/print.xtable.Rd b/pkg/man/print.xtable.Rd
new file mode 100644 (file)
index 0000000..21fb2ce
--- /dev/null
@@ -0,0 +1,57 @@
+\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="latex", file="", append=FALSE, floating=TRUE, floating.environment="table", table.placement = "ht", caption.placement="bottom", latex.environments=c("center"),tabular.environment = "tabular", size=NULL,hline.after=c(-1,0,nrow(x)), NA.string = "", include.rownames=TRUE, include.colnames=TRUE, only.contents=FALSE, add.to.row=NULL, sanitize.text.function=NULL, sanitize.rownames.function=sanitize.text.function, sanitize.colnames.function=sanitize.text.function, math.style.negative=FALSE, html.table.attributes="border=1", ...)}
+\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 are \code{"table"} or \code{"sidewaystable"} (defined in the LaTeX package 'rotating').
+                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{latex.environments}{If \code{floating=TRUE} and \code{type="latex"}, the specificed latex environments (provided as a character vector) will enclose the tabuluar 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{...}{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}}.
+}
+\author{David Dahl \email{dahl@stat.tamu.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}}}
+
+\keyword{print}
diff --git a/pkg/man/string.Rd b/pkg/man/string.Rd
new file mode 100644 (file)
index 0000000..f07fcf3
--- /dev/null
@@ -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@stat.tamu.edu} with contributions and suggestions from many others (see source code).}
+\seealso{\code{\link{print.xtable}}}
+\keyword{print}
diff --git a/pkg/man/table.attributes.Rd b/pkg/man/table.attributes.Rd
new file mode 100644 (file)
index 0000000..c109207
--- /dev/null
@@ -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@stat.tamu.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/pkg/man/tli.Rd b/pkg/man/tli.Rd
new file mode 100644 (file)
index 0000000..f6c2b43
--- /dev/null
@@ -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/pkg/man/xtable.Rd b/pkg/man/xtable.Rd
new file mode 100644 (file)
index 0000000..ab9c7ca
--- /dev/null
@@ -0,0 +1,316 @@
+\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 containing the table's caption or title.
+                 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@stat.tamu.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 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))
+
+## Demostrate 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=F ALSE, 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})
+
+\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}