\setcounter{tocdepth}{2}\r
%% Define \code \proglang and \pkg commands\r
\newcommand\code[1]{\texttt{#1}}\r
\setcounter{tocdepth}{2}\r
%% Define \code \proglang and \pkg commands\r
\newcommand\code[1]{\texttt{#1}}\r
\subsection{Time series}\r
<<results='asis'>>=\r
temp.ts <- ts(cumsum(1 + round(rnorm(100), 0)),\r
\subsection{Time series}\r
<<results='asis'>>=\r
temp.ts <- ts(cumsum(1 + round(rnorm(100), 0)),\r
<<include=FALSE>>=\r
# ## Demonstrate saving to file\r
# for(i in c("latex", "html")) {\r
<<include=FALSE>>=\r
# ## Demonstrate saving to file\r
# for(i in c("latex", "html")) {\r
\section{Helper functions for formatting}\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
\section{Helper functions for formatting}\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
\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
\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
-x.big <- xtable(x, caption = 'A \\code{longtable} spanning several pages')\r
-print(x.big, hline.after=c(-1, 0), tabular.environment = 'longtable')\r
+x.big <- xtable(x, caption = "A \\code{longtable} spanning several pages")\r
+print(x.big, hline.after=c(-1, 0), tabular.environment = "longtable")\r
-Here is an example of the use of the \code{add.to.row} argument, taken\r
-from a question on Stack Exchange:\r
-\url{http://stackoverflow.com/questions/19846796/adding-titles-to-xtable}.\r
+The following frequency table has outer dimnames: \code{Grade3} and\r
+\code{Grade6}.\r
Grade3 <- c("A","B","B","A","B","C","C","D","A","B",\r
"C","C","C","D","B","B","D","C","C","D")\r
Grade6 <- c("A","A","A","B","B","B","B","B","C","C",\r
"A","C","C","C","D","D","D","D","D","D")\r
Grade3 <- c("A","B","B","A","B","C","C","D","A","B",\r
"C","C","C","D","B","B","D","C","C","D")\r
Grade6 <- c("A","A","A","B","B","B","B","B","C","C",\r
"A","C","C","C","D","D","D","D","D","D")\r
-Cohort <- table(Grade3,Grade6)\r
-rownames(Cohort) <- 1:4\r
-colnames(Cohort) <- 5:8\r
-addtorow <- list()\r
-addtorow$pos <- list()\r
-addtorow$pos[[1]] <- 0\r
-addtorow$pos[[2]] <- 0\r
-addtorow$command <- c('& \\multicolumn{4}{c}{Grade 6} \\\\\n',\r
- "Grade 3 & A & B & C & D \\\\\n")\r
-print(xtable(Cohort, caption = 'My Title'), caption.placement = 'bottom',\r
- add.to.row = addtorow, include.colnames = FALSE,\r
- floating = TRUE)\r
+Cohort <- table(Grade3, Grade6)\r
+Cohort\r
+@\r
+\r
+\p\r
+The default behavior of \code{print.xtable} is to strip outer dimnames.\r
+<<results='asis'>>=\r
+xtable(Cohort)\r
-<<printaddtorow, echo = FALSE, results = 'asis'>>=\r
-print(xtable(Cohort, caption = 'My Title'), caption.placement = 'bottom',\r
- add.to.row = addtorow, include.colnames = FALSE,\r
- floating = TRUE)\r
-@ %def\r
+<<results='asis'>>=\r
+addtorow <- list()\r
+addtorow$pos <- list(0, 0)\r
+addtorow$command <- c("& \\multicolumn{4}{c}{Grade 6} \\\\\n",\r
+ "Grade 3 & A & B & C & D \\\\\n")\r
+print(xtable(Cohort), add.to.row = addtorow, include.colnames = FALSE)\r
+@\r
-x.side <- xtable(x, caption = 'A sideways table')\r
-print(x.side, floating = TRUE, floating.environment = 'sidewaystable')\r
+x.side <- xtable(x, caption = "A sideways table")\r
+print(x.side, floating = TRUE, floating.environment = "sidewaystable")\r
-This question appears on Stack Exchange:\\\r
-\url{http://tex.stackexchange.com/questions/12703/how-to-create-fixed-width-table-columns-with-text-raggedright-centered-raggedlef}\r
-\r
-The response is to use the \lstinline+array+ package, defining new\r
+One solution is to use the \verb|array| package, defining new\r
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\r
\arraybackslash\hspace{0pt}}m{#1}}\r
\newcolumntype{C}[1]{>{\centering\let\newline\\\r
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\r
\arraybackslash\hspace{0pt}}m{#1}}\r
\newcolumntype{C}[1]{>{\centering\let\newline\\\r
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\r
\arraybackslash\hspace{0pt}}m{#1}}\r
\newcolumntype{P}[1]{>{\raggedright\tabularxbackslash}p{#1}}\r
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\r
\arraybackslash\hspace{0pt}}m{#1}}\r
\newcolumntype{P}[1]{>{\raggedright\tabularxbackslash}p{#1}}\r
\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
\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
-<<arrayexample>>=\r
-df <- data.frame(name = c("A","B"),\r
- right = c(1.4, 34.6),\r
- left = c(1.4, 34.6),\r
- text = c("txt1","txt2"))\r
-@ %def\r
-\r
-Here is the output produced by printing an\r
-\lstinline+"xtable"+ object.\r
-\r
-<<arraytable>>=\r
-print(xtable(df, align = c("|l", "|c", "|R{3cm}","|L{3cm}","| p{3cm}|")),\r
- floating = FALSE, include.rownames = FALSE)\r
-@ %def\r
-\r
-\r
-Using the \pkg{knitr} option \code{'asis'} we obtain the table.\r
-\r
-<<arrayprint, results = 'asis'>>=\r
-print(xtable(df, align = c("|l", "|c", "|R{3cm}","|L{3cm}","| p{3cm}|")),\r
+<<results='asis'>>=\r
+df <- data.frame(name = c("A","B"), right = c(1.4, 34.6),\r
+ left = c(1.4, 34.6), text = c("txt1","txt2"))\r
+print(xtable(df, align = c("l", "|c", "|R{3cm}", "|L{3cm}", "| p{3cm}|")),\r