### Feature request #2248, 2/9/2012
xtableFtable <- function(x, caption = NULL, label = NULL, align = NULL,
digits = NULL, display = NULL,
- quote = TRUE,
+ quote = FALSE,
method = c("non.compact", "row.compact",
"col.compact", "compact"),
lsep = " | ", ...) {
}
}
if (method == "non.compact"){
- nCharCols <- nRowVars + 1
+ nCharCols <- nRowVars + 2
nCharRows <- nColVars + 1
}
if (method == "row.compact"){
- nCharCols <- nRowVars + 1
+ nCharCols <- nRowVars + 2
nCharRows <- nColVars
}
if (method == "col.compact"){
- nCharCols <- nRowVars
+ nCharCols <- nRowVars + 1
nCharRows <- nColVars + 1
}
if (method == "compact"){
- nCharCols <- nRowVars
+ nCharCols <- nRowVars + 1
nCharRows <- nColVars
}
-
- if(is.null(align)) align <- c(rep("l", nCharCols), rep("r", xDim[2]))
+
+ if(is.null(align)) {
+ align <- c(rep("l", nCharCols - 1), "l |", rep("r", xDim[2]))
+ }
if(is.null(display)) {
display <- c(rep("s", nCharCols), rep("d", xDim[2]))
}
-
+
attr(x, "ftableCaption") <- caption
attr(x, "ftableLabel") <- label
attr(x, "ftableAlign") <- align
...) {
if (type == "latex"){
caption <- attr(x, "ftableCaption")
- label <- attr(x, "ftableLabel")
+ label <- attr(x, "ftableLabel")
align <- attr(x, "ftableAlign")
- digits <- attr(x, "ftableDigits")
+ digits <- attr(x, "ftableDigits")
quote <- attr(x, "quote")
digits <- attr(x, "ftabelDigits")
method <- attr(x, "method")
attr(fmtFtbl, "align") <- align
attr(fmtFtbl, "digits") <- digits
attr(fmtFtbl, "quote") <- quote
- attr(fmtFtbl, "display") <- display
+ attr(fmtFtbl, "display") <- display
print.xtable(fmtFtbl, hline.after = c(-1, nCharRows, dim(fmtFtbl)[1]),
include.rownames = FALSE, include.colnames = FALSE)
} else {
temp.table\r
@\r
\r
+\subsection{Flat tables}\r
+\label{sec:flat-tables}\r
+\r
+See the \textbf{Details} section of the help for \code{ftable} for a\r
+description of these tables, which are flat versions of\r
+multi-dimensional contingency tables. They require special methods to\r
+enable them to be printed using \pkg{xtable}\r
+\r
+\r
+<<ftable>>=\r
+data(mtcars)\r
+tbl <- ftable(mtcars$cyl, mtcars$vs, mtcars$am, mtcars$gear,\r
+ row.vars = c(2, 4),\r
+ dnn = c("Cylinders", "V/S", "Transmission", "Gears"))\r
+\r
+@ %def\r
+\r
+\p\r
+<<ftable1, results = 'asis'>>=\r
+xftbl <- xtableFtable(tbl)\r
+print.xtableFtable(xftbl)\r
+@ %def\r
+\r
+\p\r
+<<ftable2, results = 'asis'>>=\r
+xftbl <- xtableFtable(tbl, method = "row.compact")\r
+print.xtableFtable(xftbl)\r
+@ %def\r
+\r
+\p\r
+<<ftable3, results = 'asis'>>=\r
+xftbl <- xtableFtable(tbl, method = "col.compact")\r
+print.xtableFtable(xftbl)\r
+@ %def\r
+\r
+\p\r
+<<ftable4, results = 'asis'>>=\r
+xftbl <- xtableFtable(tbl, method = "compact")\r
+print.xtableFtable(xftbl)\r
+@ %def\r
+\r
\newpage\r
\r
<<include=FALSE>>=\r
\r
\section{Automatic formatting}\r
\subsection{Suggest alignment, digits, and display}\r
-The functions \code{xalign}, \code{xdigits}, and \code{xdisplay} are useful for\r
-formatting tables in a sensible way. Consider the output produced by the default\r
-formatting.\r
+The functions \code{xalign}, \code{xdigits}, and \code{xdisplay} are\r
+useful for formatting tables in a sensible way. Consider the output\r
+produced by the default formatting.\r
\r
<<results='asis'>>=\r
dat <- mtcars[1:3, 1:6]\r
row.names = c("A","B")),\r
display = c("s","s","g","g")),\r
math.style.exponents = TRUE)\r
-@ \r
+@\r
\r
this option also supports the values \code{ensuremath} which uses\r
\code{\char`\\ensuremath} instead of \code{\$\$} and \code{UTF-8}\r
\newpage\r
\r
\subsection{Markup in tables}\r
-Markup can be included in tables, including in column and row names, by using\r
-a custom \code{sanitize.text.function}.\r
+Markup can be included in tables, including in column and row names,\r
+by using a custom \code{sanitize.text.function}.\r
\r
<<results='asis'>>=\r
mat <- round(matrix(c(0.9, 0.89, 200, 0.045, 2.0), c(1, 5)), 4)\r
\newpage\r
\r
\subsection{Rotate row/column names}\r
-The \code{rotate.rownames} and \code{rotate.colnames} arguments can be used to\r
-rotate the row and/or column names. This requires \verb|\usepackage{rotating}|\r
-in the \LaTeX\ preamble.\r
+The \code{rotate.rownames} and \code{rotate.colnames} arguments can be\r
+used to rotate the row and/or column names. This requires\r
+\verb|\usepackage{rotating}| in the \LaTeX\ preamble.\r
\r
<<results='asis'>>=\r
print(tli.table, rotate.rownames = TRUE, rotate.colnames = TRUE)\r
@\r
\r
\subsubsection{Line styles}\r
-Specifying \code{booktabs = TRUE} will generate three line types. By default,\r
-when no value is given for \code{hline.after}, a \verb|\toprule| will be drawn\r
-above the table, a \verb|\midrule| after the table headings and a\r
-\verb|\bottomrule| below the table. This requires \verb|\usepackage{booktabs}|\r
-in the \LaTeX\ preamble.\r
+Specifying \code{booktabs = TRUE} will generate three line types. By\r
+default, when no value is given for \code{hline.after}, a\r
+\verb|\toprule| will be drawn above the table, a \verb|\midrule| after\r
+the table headings and a \verb|\bottomrule| below the table. This\r
+requires \verb|\usepackage{booktabs}| in the \LaTeX\ preamble.\r
\r
\p\r
-The top and bottom rules are slightly thicker than the mid rule. The thickness\r
-of the lines can be set via the \LaTeX\ lengths \verb|\heavyrulewidth| and\r
-\verb|\lightrulewidth|.\r
+\r
+The top and bottom rules are slightly thicker than the mid rule. The\r
+thickness of the lines can be set via the \LaTeX\ lengths\r
+\verb|\heavyrulewidth| and \verb|\lightrulewidth|.\r
\r
<<results='asis'>>=\r
tli.table <- xtable(tli[1:10, ])\r
@\r
\r
\p\r
+\r
If \code{hline.after} includes \code{-1}, a \verb|\toprule| will be\r
drawn above the table. If \code{hline.after} includes the number of\r
rows in the table, a \verb|\bottomrule| will be drawn below the\r
"\\multicolumn{", dim(x)[2] + 1, "}{l}",\r
"{\\footnotesize Continued on next page}\n",\r
"\\endfoot\n",\r
- "\\endlastfoot\n") \r
+ "\\endlastfoot\n")\r
add.to.row$command <- command\r
print(x.big, hline.after=c(-1), add.to.row = add.to.row,\r
tabular.environment = "longtable")\r
These allow for very sophisticated cell formatting, namely\r
left-aligned, centred, or right-aligned text, with recognition of line\r
breaks for the first three new column types. If these lines are\r
-included along with \verb|\usepackage{array}|, then the following\r
-is possible.\r
+included along with \verb|\usepackage{array}|, then the following is\r
+possible.\r
\r
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\r
\arraybackslash\hspace{0pt}}m{#1}}\r
\newpage\r
\r
\subsection{Table width}\r
-The \code{tabularx} environment is for typesetting tables whose overall width is\r
-fixed. The column alignment code \code{X} denotes columns that will be stretched\r
-to achieve the desired table width. Requires \verb|\usepackage{tabularx}| in the\r
-\LaTeX\ preamble.\r
+The \code{tabularx} environment is for typesetting tables whose\r
+overall width is fixed. The column alignment code \code{X} denotes\r
+columns that will be stretched to achieve the desired table\r
+width. Requires \verb|\usepackage{tabularx}| in the \LaTeX\ preamble.\r
\r
<<results='asis'>>=\r
df.width <- data.frame(One = c("item 1", "A"), Two = c("item 2", "B"),\r
@\r
\r
\section{Suppressing printing}\r
-By default the \code{print} method will print the \LaTeX\ or HTML to standard\r
-output and also return the character strings invisibly. The printing to\r
-standard output can be suppressed by specifying \code{print.results = FALSE}.\r
+By default the \code{print} method will print the \LaTeX\ or HTML to\r
+standard output and also return the character strings invisibly. The\r
+printing to standard output can be suppressed by specifying\r
+\code{print.results = FALSE}.\r
\r
<<>>=\r
x.out <- print(tli.table, print.results = FALSE)\r
x.ltx\r
@\r
\r
+\r
\newpage\r
\r
\section{Acknowledgements}\r