%\VignetteIndexEntry{xtable List of Tables Gallery} %\VignetteDepends{xtable} %\VignetteKeywords{LaTeX, HTML, table} %\VignettePackage{xtable} % !Rnw weave = knitr % \VignetteEngine{knitr::knitr} %************************************************************************** \documentclass{article} \usepackage[a4paper,height=24cm]{geometry} % geometry first \usepackage{array} \usepackage{booktabs} \usepackage{longtable} \usepackage{parskip} \usepackage{rotating} \usepackage{tabularx} \usepackage{titlesec} \usepackage{hyperref} % hyperref last \titleformat\subsubsection{\bfseries\itshape}{}{0pt}{} \newcommand\p{\vspace{2ex}} \newcommand\code[1]{\texttt{#1}} \newcommand\pkg[1]{\textbf{#1}} \setcounter{tocdepth}{2} \begin{document} \title{\bfseries\Large The \code{xtableList} Gallery} \author{\bfseries David J. Scott} \maketitle \tableofcontents \newpage \section{Introduction} This document represents a test of the functions in \pkg{xtable} which deal with lists of dataframes. <>= library(knitr) opts_chunk$set(fig.path='Figures/list', debug=TRUE, echo=TRUE) opts_chunk$set(out.width='0.9\\textwidth') @ The first step is to load the package and set some options for this document. <>= library(xtable) options(xtable.floating = FALSE) options(xtable.timestamp = "") options(width = 60) @ Next we create a list of dataframes with attributes. <>= require(xtable) data(mtcars) mtcars <- mtcars[, 1:6] mtcarsList <- split(mtcars, f = mtcars$cyl) ### Reduce the size of the list elements mtcarsList[[1]] <- mtcarsList[[1]][1,] mtcarsList[[2]] <- mtcarsList[[2]][1:2,] mtcarsList[[3]] <- mtcarsList[[3]][1:3,] attr(mtcarsList, "subheadings") <- paste0("Number of cylinders = ", names(mtcarsList)) attr(mtcarsList, "message") <- c("Line 1 of Message", "Line 2 of Message") str(mtcarsList) attributes(mtcarsList) @ %def Now create a list of \code{xtable} objects. <>= xList <- xtableList(mtcarsList) str(xList) @ %def Create an alternative version where the lists have different values for \code{digits}. <>= xList1 <- xtableList(mtcarsList, digits = c(0,2,0,0,0,1,2)) str(xList1) @ %def <>= xList2 <- xtableList(mtcarsList, digits = c(0,2,0,0,0,1,2), caption = "Caption to List", label = "tbl:xtableList") str(xList2) @ %def Further versions with no subheadings, and no message <>= attr(mtcarsList, "subheadings") <- NULL xList3 <- xtableList(mtcarsList) str(xList3) @ %def <>= attr(mtcarsList, "message") <- NULL xList4 <- xtableList(mtcarsList) str(xList4) @ %def \newpage \section{Single Column Names} \label{sec:single-column-names} Print the list of \code{xtable} objects with a single header of the column names. First the default. <>= print.xtableList(xList) @ %def Booktabs should work. <>= print.xtableList(xList, booktabs = TRUE) @ %def With digits being specified. <>= print.xtableList(xList1, booktabs = TRUE) @ %def Row and column names, subheadings, and the message can be sanitized. <>= large <- function(x){ paste0('{\\Large{\\bfseries ', x, '}}') } italic <- function(x){ paste0('{\\emph{ ', x, '}}') } bold <- function(x){ paste0('{\\bfseries ', x, '}') } red <- function(x){ paste0('{\\color{red} ', x, '}') } @ %def <>= print.xtableList(xList, sanitize.rownames.function = italic, sanitize.colnames.function = large, sanitize.subheadings.function = bold, sanitize.message.function = red, booktabs = TRUE) @ %def A label and caption can be added. <>= print.xtableList(xList2, floating = TRUE) @ %def Rotated column names? <>= print.xtableList(xList, rotate.colnames = TRUE) @ %def No subheadings? <>= print.xtableList(xList3) @ %def No message? <>= print.xtableList(xList4) @ %def \section{Multiple Column Names} \label{sec:multiple-column-names} Print the list of \code{xtable} objects with multiple headers of the column names. First the default with multiple column name headers. <>= print.xtableList(xList, colnames.format = "multiple") @ %def Using booktabs: <>= print.xtableList(xList, colnames.format = "multiple", booktabs = TRUE) @ %def With sanitization. <>= print.xtableList(xList, colnames.format = "multiple", sanitize.rownames.function = italic, sanitize.colnames.function = large, sanitize.subheadings.function = bold, sanitize.message.function = red, booktabs = TRUE) @ %def A label and caption can be added. <>= print.xtableList(xList2, colnames.format = "multiple", floating = TRUE) @ %def Rotated column names? <>= print.xtableList(xList, colnames.format = "multiple", rotate.colnames = TRUE) @ %def No subheadings? <>= print.xtableList(xList3, colnames.format = "multiple") @ %def No message? <>= print.xtableList(xList4, colnames.format = "multiple") @ %def \end{document}