]> git.donarmstrong.com Git - xtable.git/commitdiff
Finished documentation changes to xtableFtable and xtableList. Package should be...
authordscott <dscott@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Thu, 28 Jan 2016 04:22:53 +0000 (04:22 +0000)
committerdscott <dscott@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Thu, 28 Jan 2016 04:22:53 +0000 (04:22 +0000)
git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@103 edb9625f-4e0d-4859-8d74-9fd3b1da38cb

pkg/NAMESPACE
pkg/NEWS
pkg/R/sanitize.R
pkg/R/xtableFtable.R
pkg/man/sanitize.Rd
pkg/man/xtableFtable.Rd
pkg/man/xtableList.Rd

index 77c56f09145921edaac0f9479737cc4fbefb9d55..f5c4c6987a5c21ca17ba87af5d236e8d57813866 100644 (file)
@@ -10,7 +10,7 @@ export("caption<-", "caption", "label", "label<-",
        "xtableFtable", "print.xtableFtable",
        "toLatex.xtable",
        "autoformat", "xalign", "xdigits", "xdisplay",
-       "sanitize", "sanitize.numbers", "sanitize.final")
+       "sanitize", "sanitize.numbers", "sanitize.final", "as.is", "as.math")
 
 S3method("print", "xtable")
 S3method("print", "xtableMatharray")
index 9687f7d840fcf0ab31ee18bc6ac4a861a3f2a3cf..057abe082731446c443db419747e2661c9448a0c 100644 (file)
--- a/pkg/NEWS
+++ b/pkg/NEWS
@@ -7,9 +7,11 @@
     tables from the spatial econometrics packages, spdep, splm, and
     sphet.
   * Extracted sanitize functions from print.xtable as stand-alone
-    functions, and exported them.
+    functions, and exported them. Added helper functions as.is and
+    as.math for assistance with sanitization (supplied by Stefan
+    Edwards <sme@iysik.com> in Feature Request #5303).
   * Added option to produce math style exponents when sanitizing
-    numbers, as suggested by Don Armstrong (don@donarmstrong.com), who
+    numbers, as suggested by Don Armstrong <don@donarmstrong.com>, who
     also provided code
   * Fixed bug #6907. Warning was created when the data frame as no
     rows for type is 'html'. Added a test to create the matrix
     Loehnert, which was to replace { and } by \begingroup and
     \endgroup respectively as the delimiters when size was to changed
     in a table.
-
+  * Added functions xtableList and print.xtableList to produce
+    composite tables consisting of a number of subtables.
+  * Added xtableFtable and print.xtableFtable to format flat tables
+    produced by ftable. Included examples in the xtable gallery.
+  * Produced new vignettes: 'The xtableList Gallery' to illustrate
+    xtableList and print.xtableList; and 'The Other Packages Gallery'
+    to illustrate methods for classes of objects from other packages.
 
 1.8-0
   * autoformat, xalign, xdigits, xdisplay from Arni Magnusson, added
index c31a660f7fd8bcc84191d53288a8902536744116..b5b83cf984135f1d191dbb6669cb34f24a3e0761 100644 (file)
@@ -87,3 +87,11 @@ sanitize.final <- function(str, type){
     return(str)
   }
 }
+
+### Some trivial helper functions
+### Suggested by Stefan Edwards, sme@iysik.com
+### Helper function for disabling sanitizing
+as.is <- function(str) {str}
+
+### Helper function for embedding names in a math environment
+as.math <- function(str, ...) { paste0('$',str,'$', ...) }
index c4e036963be2ff5e16fdc2c8838dcbc74f61b4db..34b544df833b0f39aa1d02bb5463fdeadf15f6cd 100644 (file)
@@ -78,8 +78,7 @@ print.xtableFtable <- function(x,
   NA.string = getOption("xtable.NA.string", ""),
   only.contents = getOption("xtable.only.contents", FALSE),
   add.to.row = getOption("xtable.add.to.row", NULL),
-  sanitize.text.function = getOption("xtable.sanitize.text.function",
-                                     function(x){x}),
+  sanitize.text.function = getOption("xtable.sanitize.text.function", as.is),
   sanitize.rownames.function = getOption("xtable.sanitize.rownames.function",
                                          sanitize.text.function),
   sanitize.colnames.function = getOption("xtable.sanitize.colnames.function",
@@ -182,7 +181,7 @@ print.xtableFtable <- function(x,
     print.xtable(fmtFtbl, hline.after = hline.after,
                  include.rownames = FALSE, include.colnames = FALSE,
                  booktabs = booktabs,
-                 sanitize.text.function = function(x){x})
+                 sanitize.text.function = as.is)
   } else {
     stop("print.xtableFtable not yet implemented for this type")
   }
index 3bba1072e6ee4b31800932c0833a75aae2c8ca63..5b65808de75afeedac5f584e7a33524e1b25e3f7 100644 (file)
@@ -2,6 +2,8 @@
 \alias{sanitize}\r
 \alias{sanitize.numbers}\r
 \alias{sanitize.final}\r
+\alias{as.is}\r
+\alias{as.math}\r
 \r
 \title{\r
   Sanitization Functions\r
@@ -16,6 +18,8 @@ sanitize(str, type)
 sanitize.numbers(str, type, math.style.negative = FALSE,\r
                  math.style.exponents = FALSE)\r
 sanitize.final(str, type)\r
+as.is(str)\r
+as.math(str, ...)\r
 }\r
 \r
 \arguments{\r
@@ -32,6 +36,8 @@ sanitize.final(str, type)
     for 5e5. If \code{"UTF-8"} or \code{"UTF-8"}, then use UTF-8 to\r
     approximate the LaTeX typsetting for 5e5.\r
     Default value is \code{FALSE}.}\r
+  \item{\dots}{Additional arguments. Character strings or character\r
+    vectors.}\r
 }\r
 \details{\r
 \r
@@ -59,6 +65,10 @@ sanitize.final(str, type)
   effect. When \code{type} is \code{"html"}, multiple spaces are\r
   replaced by a single space and occurrences of \code{' align="left"'}\r
   are eliminated.\r
+\r
+  \code{as.is} and \code{as.math} are trivial helper functions to\r
+  disable sanitizing and to insert a some mathematics in a string\r
+  respectively.\r
 }\r
 \value{\r
   Returns the sanitized character object.\r
@@ -70,10 +80,11 @@ sanitize.final(str, type)
   Swinton <jonathan@swintons.net>, Uwe Ligges\r
   <ligges@statistik.uni-dortmund.de>, and probably David B. Dahl\r
   <dahl@stat.byu.edu>.\r
+  \code{as.is} and \code{as.math} suggested and provided by Stefan\r
+  Edwards <sme@iysik.com>.\r
 }\r
 \r
 \examples{\r
-\r
 insane <- c("&",">", ">","_","\%","$","\\\\","#","^","~","{","}")\r
 names(insane) <- c("Ampersand","Greater than","Less than",\r
                    "Underscore","Percent","Dollar",\r
@@ -87,6 +98,8 @@ x <- rnorm(10)
 sanitize.numbers(x, "latex", TRUE)\r
 sanitize.numbers(x*10^(10), "latex", TRUE, TRUE)\r
 sanitize.numbers(x, "html", TRUE, TRUE)\r
+as.is(insane)\r
+as.math("x10^10", ": mathematical expression")\r
 }\r
 \r
 \keyword{print }\r
index 6e783a72502af6bf6a5a144dc137b195e577b997..5d6b2dc9d120d65ffcd838b99bf68fd386787368 100644 (file)
@@ -35,8 +35,7 @@ xtableFtable(x, caption = NULL, label = NULL,
   NA.string = getOption("xtable.NA.string", ""),
   only.contents = getOption("xtable.only.contents", FALSE),
   add.to.row = getOption("xtable.add.to.row", NULL),
-  sanitize.text.function = getOption("xtable.sanitize.text.function",
-                                     function(x){x}),
+  sanitize.text.function = getOption("xtable.sanitize.text.function", as.is),
   sanitize.rownames.function = getOption("xtable.sanitize.rownames.function",
                                          sanitize.text.function),
   sanitize.colnames.function = getOption("xtable.sanitize.colnames.function",
@@ -202,14 +201,11 @@ xtableFtable(x, caption = NULL, label = NULL,
     of the same length as the first component, which contains the command
     that should be added at the end of the specified rows.
     Default value is \code{NULL}, i.e. do not add commands.}
-  \item{sanitize.text.function}{All non-numeric entries (except row and
-    column names) are sanitized in an attempt to remove characters which
-    have special meaning for the output format. If
-    \code{sanitize.text.function} is not \code{NULL}, 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.
-    Default value is \code{NULL}.}
+  \item{sanitize.text.function}{Since the table entries are counts no
+    sanitization is necessary. The default is \code{as.is}, which is the
+    function which makes no changes. This also applies to the labels for
+    the row and column variables since these are also part of the table
+    which is printed using a call to \code{print.xtable}.}
   \item{sanitize.rownames.function}{Like the
     \code{sanitize.text.function}, but applicable to row names.
     The default uses the \code{sanitize.text.function}. }
index ce66636d8326434c77dcaa09c0f9d3dc7f656a13..1682689cc2cb5dca13e606f35169980507b732c0 100644 (file)
@@ -60,8 +60,13 @@ xtableList(x, caption = NULL, label = NULL,
   ...)\r
 }\r
 \arguments{\r
-  \item{x}{For \code{xtableList}, a list of \R objects all of the same\r
-    class, being a class found among \code{methods(xtable)}.\r
+  \item{x}{\r
+    For \code{xtableList}, a list of \R objects all of the same class,\r
+    being a class found among \code{methods(xtable)}. The list may also\r
+    have attributes \code{"subheadings"} and \code{"message"}. The\r
+    attribute \code{"subheadings"} should be a character vector of the\r
+    same length as the list \code{x}. The attribute \code{"message"}\r
+    should be a character vector of any length.\r
     For \code{print.xtableList}, an object of class \code{xtableList}\r
     produced by a call to \code{xtableList}.}\r
   \item{caption}{Character vector of length 1 or 2 containing the\r
@@ -247,14 +252,54 @@ xtableList(x, caption = NULL, label = NULL,
   \item{\dots}{Additional arguments.  (Currently ignored.)}\r
 }\r
 \details{\r
-%%  ~~ If necessary, more details than the description above ~~\r
+  \code{xtableList} produces an object suitable for printing using\r
+  \code{print.xtableList}.\r
+\r
+  The elements of the list \code{x} supplied to \code{xtableList} must\r
+  all have the same structure. When these list items are submitted to\r
+  \code{xtable} the resulting table must have the same number of columns\r
+  with the same column names and type of data.\r
+\r
+  The values supplied to arguments \code{digits} and \code{display},\r
+  must be composed of elements as specified in those same arguments for\r
+  the function \code{\link{xtable}}. See the help for\r
+  \code{\link{xtable}} for details.\r
+\r
+  \code{print.xtableList} produces tables in two different formats\r
+  depending on the value of \code{col.names.format}. If\r
+  \code{col.names.format = "single"}, the resulting table has only a\r
+  single heading row. If \code{col.names.format = "multiple"} there is a\r
+  heading row for each of the subtables making up the complete table.\r
+\r
+  By default if \code{col.names.format = "single"}, there are horizontal\r
+  lines above and below the heading row, and at the end of each\r
+  subtable. If \code{col.names.format = "multiple"}, there are\r
+  horizontal lines above and below each appearance of the heading row,\r
+  and at the end of each subtable.\r
+\r
+  If \code{"subheadings"} is not \code{NULL}, the individual elements of\r
+  this vector (which can include newlines \verb{\\n}) produce a heading\r
+  line or lines for the subtables. When \code{col.names.format =\r
+    "multiple"} these subheadings appear \emph{above} the heading rows.\r
+\r
+  If \code{"message"} is not \code{NULL} the vector produces a line or\r
+  lines at the end of the table.\r
+\r
+  Consult the vignette \sQuote{The \code{xtableList} Gallery} to see\r
+  the behaviour of these functions.\r
+\r
+  Note that at present there is no code for \code{type = "html"}.\r
 }\r
 \value{\r
-%%  ~Describe the value returned\r
-%%  If it is a LIST, use\r
-%%  \item{comp1 }{Description of 'comp1'}\r
-%%  \item{comp2 }{Description of 'comp2'}\r
-%% ...\r
+  \code{xtableList} produces an object of class\r
+  \code{"xtableList"}. An object of this class is a list of\r
+  \code{"xtable"} objects with some additional attributes. Each element\r
+  of the list can have a \code{"subheading"} attribute. The list can\r
+  also have a \code{"message"} attribute.\r
+\r
+  \code{print.xtableList} produces a character string containing LaTeX\r
+  markup which produces a nicely formatted table comprised of subtables,\r
+  when included in a LaTeX document.\r
 }\r
 \author{\r
   David Scott \email{d.scott@auckland.ac.nz}.\r
@@ -269,8 +314,18 @@ xtableList(x, caption = NULL, label = NULL,
 \seealso{\r
   \code{\link{xtable}}, \code{\link{caption}}, \code{\link{label}},\r
   \code{\link{align}}, \code{\link{digits}}, \code{\link{display}},\r
-  \code{\link{formatC}}\r
+  \code{\link{formatC}}, \code{\link{print.xtable}}.\r
 }\r
 \examples{\r
+data(mtcars)\r
+mtcars <- mtcars[, 1:6]\r
+mtcarsList <- split(mtcars, f = mtcars$cyl)\r
+attr(mtcarsList, "subheadings") <- paste0("Number of cylinders = ",\r
+                                          names(mtcarsList))\r
+attr(mtcarsList, "message") <- c("Line 1 of Message",\r
+                                 "Line 2 of Message")\r
+xList <- xtableList(mtcarsList)\r
+print.xtableList(xList)\r
+print.xtableList(xList, colnames.format = "multiple")\r
 }\r
 \keyword{ print }\r