[Rd] Suggestion: 'method' slot for format.ftable()

Marius Hofert marius.hofert at math.ethz.ch
Sat Dec 22 21:56:09 CET 2012


Dear Martin,

Thanks a lot, that sounds great. Here is the unified diff for ?read.ftable.Rd.

Cheers,

Marius

--- /home/mhofert/R/R-devel/src/library/stats/man/read.ftable.Rd	2012-12-21 02:09:18.488980586 +0100
+++ read.ftable.Rd	2012-12-22 21:45:08.574636009 +0100
@@ -14,9 +14,13 @@
             row.var.names, col.vars, skip = 0)
 
 write.ftable(x, file = "", quote = TRUE, append = FALSE,
-             digits = getOption("digits"))
-
-\method{format}{ftable}(x, quote = TRUE, digits = getOption("digits"), \dots)
+             digits = getOption("digits"),
+             method=c("non.compact", "row.compact", "col.compact", "compact"),
+             sep=" \\ ")
+
+\method{format}{ftable}(x, quote = TRUE, digits = getOption("digits"),
+                        method=c("non.compact", "row.compact",
+                                 "col.compact", "compact"), sep=" \\ ", \dots)
 }
 \arguments{
   \item{file}{either a character string naming a file or a connection
@@ -42,6 +46,22 @@
     the contents of \code{file} will be overwritten.}
   \item{digits}{an integer giving the number of significant digits to
     use for (the cell entries of) \code{x}.}
+  \item{method}{methods of how the formatted \code{"ftable"} object is
+    printed. Available are (see the examples):
+    \describe{
+      \item{"non.compact"}{the default representation of an
+        \code{"ftable"} object.}
+      \item{"row.compact"}{a row-compact version without empty cells
+        under the column labels.}
+      \item{"col.compact"}{a column-compact version without empty cells
+        to the right of the row labels.}
+      \item{"compact"}{a row- and column-compact version. This may imply
+        that a row and a column label have to share the
+        same cell. They are then separated by the character
+        specified by \code{sep}.}
+  }}
+  \item{sep}{separation character for row/column labels if
+    \code{method="compact"}.}
   \item{\dots}{further arguments to be passed to or from methods.}
 }
 \details{
@@ -64,7 +84,9 @@
   table from this using \code{\link{xtabs}}.
 
   \code{write.ftable} writes a flat table to a file, which is useful for
-  generating \sQuote{pretty} ASCII representations of contingency tables.
+  generating \sQuote{pretty} ASCII representations of contingency
+  tables. Different versions are available via the \code{method}
+  argument, which may be useful, for example, for constructing LaTeX tables.
 }
 \seealso{
   \code{\link{ftable}} for more information on flat contingency tables.
@@ -108,6 +130,9 @@
 
 ft22 <- ftable(Titanic, row.vars = 2:1, col.vars = 4:3)
 write.ftable(ft22, quote = FALSE)
+write.ftable(ft22, quote = FALSE, method="row.compact")
+write.ftable(ft22, quote = FALSE, method="col.compact")
+write.ftable(ft22, quote = FALSE, method="compact")
 \dontshow{
 stopifnot(dim(format(ft)) == 4:5,
           dim(format(ftable(UCBAdmissions))) == c(6,9),



More information about the R-devel mailing list