]> git.donarmstrong.com Git - xtable.git/commitdiff
Added "toLatex()" method. Added "print.result" argument to "print.xtable()" function.
authorroosen <roosen@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Mon, 30 Jan 2012 09:40:38 +0000 (09:40 +0000)
committerroosen <roosen@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Mon, 30 Jan 2012 09:40:38 +0000 (09:40 +0000)
git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@18 edb9625f-4e0d-4859-8d74-9fd3b1da38cb

pkg/DESCRIPTION
pkg/NAMESPACE
pkg/NEWS
pkg/R/print.xtable.R
pkg/R/toLatex.R [new file with mode: 0644]
pkg/inst/doc/xtableGallery.snw
pkg/man/print.xtable.Rd
pkg/man/toLatex.Rd [new file with mode: 0644]

index 40d1eaeb2cd2213485fbe5195998c659c809b87c..4c8eab308cf8b0efdf7f33fa13bd43de1a10fcb2 100644 (file)
@@ -1,5 +1,5 @@
 Package: xtable
-Version: 1.6-0
+Version: 1.6-1
 Date: 2011/10/06
 Title: Export tables to LaTeX or HTML
 Author: David B. Dahl <dahl@stat.tamu.edu>
index 521cf2d629fd4d287b19d4e99be42e12ee2a3ebd..52dbdd6096992d305412c97fc99d1ac339866b59 100644 (file)
@@ -1,11 +1,17 @@
 # NAMESPACE work by Robert Gentleman <rgentlem@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")
+   "display", "xtable", "print.xtable", "toLatex.xtable")
 
 S3method("print", "xtable")
+S3method("toLatex", "xtable")
+
 S3method("caption<-", "xtable")
 S3method("caption", "xtable")
 S3method("label", "xtable")
@@ -16,6 +22,7 @@ S3method("digits", "xtable")
 S3method("digits<-", "xtable")
 S3method("display<-", "xtable")
 S3method("display", "xtable")
+
 S3method("xtable", "data.frame")
 S3method("xtable", "matrix")
 S3method("xtable", "table")
index f085dc605ec4b512d858cb9c674201ca2d8a662d..a2469ae2fbbe6448d29c60a209cf300b78acd854 100644 (file)
--- a/pkg/NEWS
+++ b/pkg/NEWS
@@ -1,3 +1,11 @@
+1.6-1 (NOT YET RELEASED)
+
+  * Added some vectorization code to improve performance.
+  * Added "toLatex" method.
+  * Included "print" in the exported methods in the NAMESPACE file.
+  * Added "print.result" argument to "print" that can be used to
+    suppress the printing.
+
 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.
index c20fb6212a31c92b07ab8e1538692a145058bdb9..c51793948e526dc9e775021b0e2805b20165e355 100644 (file)
@@ -44,6 +44,7 @@ print.xtable <- function(
   sanitize.colnames.function=sanitize.text.function,\r
   math.style.negative=FALSE,\r
   html.table.attributes="border=1",\r
+  print.result=TRUE,\r
   ...) {\r
   # Claudio Agostinelli <claudio@unive.it> dated 2006-07-28 hline.after\r
   # By default it print an \hline before and after the columns names independently they are printed or not and at the end of the table\r
@@ -419,8 +420,10 @@ print.xtable <- function(
     result <- result + ETABLE\r
   }   \r
   result <- sanitize.final(result)\r
-  print(result)\r
-\r
+  if (print.result){\r
+       print(result)\r
+  }\r
+  \r
   return(invisible(result$text))\r
 }\r
 \r
diff --git a/pkg/R/toLatex.R b/pkg/R/toLatex.R
new file mode 100644 (file)
index 0000000..3a2ba58
--- /dev/null
@@ -0,0 +1,40 @@
+### xtable package\r
+###\r
+### Produce LaTeX and HTML tables from R objects.\r
+###\r
+### Copyright 2000-2012 David B. Dahl <dahl@stat.tamu.edu>\r
+###\r
+### Maintained by Charles Roosen <croosen@mango-solutions.com>\r
+###\r
+### This file is part of the `xtable' library for R and related languages.\r
+### It is made available under the terms of the GNU General Public\r
+### License, version 2, or at your option, any later version,\r
+### incorporated herein by reference.\r
+###\r
+### This program is distributed in the hope that it will be\r
+### useful, but WITHOUT ANY WARRANTY; without even the implied\r
+### warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR\r
+### PURPOSE.  See the GNU General Public License for more\r
+### details.\r
+###\r
+### You should have received a copy of the GNU General Public\r
+### License along with this program; if not, write to the Free\r
+### Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,\r
+### MA 02111-1307, USA\r
+\r
+## The generic for toLatex() is declared in the base package "utils"\r
+\r
+toLatex.xtable <- function(object, ...){\r
+  # Initially just capturing the output of print.xtable().  At some\r
+  # point this could be refactored to have print.xtable() call\r
+  # toLatex() instead. - CR, 30/01/2012\r
+  dotArgs <- list(...)\r
+  dotArgs$x <- object\r
+  dotArgs$type <- "latex"\r
+  dotArgs$print.result <- FALSE\r
+  z <- do.call("print.xtable", dotArgs)\r
+\r
+  z <- strsplit(z, split="\n")[[1]]\r
+  class(z) <- "Latex"\r
+  z\r
+}\r
index 995db16da7a68c5a09c250325b96a0e363f627cd..39eb05ecbb4c41e9f1efcf682905a7bd5774bd0d 100644 (file)
@@ -431,6 +431,28 @@ print(x.small,floating.environment='sidewaystable')
 @
 \clearpage
 
+\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 supproessed by specifying {\tt print.result = FALSE}.
+
+<<>>=
+# This will print the output and store it.
+x.out <- print(tli.table)
+
+# This will just store the value.
+x.out2 <- print(tli.table, print.results = FALSE)
+@
+
+Formatted output can also be captured without the printing with the
+{\tt toLatex} method.
+
+<<>>=
+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}
index 0e32eb4eebddcefdd67be28f551eda226d93980d..55ccf42d05b52f8b01c8a5dc50cff64210a0f3e4 100644 (file)
@@ -10,7 +10,8 @@
                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", ...)}
+               html.table.attributes="border=1", 
+               print.result=TRUE, ...)}
 \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"}.
@@ -43,6 +44,7 @@
   \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.result}{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{...}{Additional arguments.  (Currently ignored.)}
 }
 \details{
diff --git a/pkg/man/toLatex.Rd b/pkg/man/toLatex.Rd
new file mode 100644 (file)
index 0000000..e0cc1cc
--- /dev/null
@@ -0,0 +1,17 @@
+\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@gmail.com} with contributions and suggestions from many others (see source code).}
+\seealso{\code{\link{print.xtable}}}
+
+\keyword{toLatex}