1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
## ----set, include=FALSE--------------------------------------------------
library(knitr)
opts_chunk$set(fig.path='Figures/list', debug=TRUE, echo=TRUE)
opts_chunk$set(out.width='0.9\\textwidth')
## ----package, results='asis'------------------------------
library(xtable)
options(xtable.floating = FALSE)
options(xtable.timestamp = "")
options(width = 60)
## ----data-------------------------------------------------
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)
## ----xtablelist-------------------------------------------
xList <- xtableList(mtcarsList)
str(xList)
## ----xtablelist1------------------------------------------
xList1 <- xtableList(mtcarsList, digits = c(0,2,0,0,0,1,2))
str(xList1)
## ----xtablelist2------------------------------------------
xList2 <- xtableList(mtcarsList, digits = c(0,2,0,0,0,1,2),
caption = "Caption to List",
label = "tbl:xtableList")
str(xList2)
## ----xtablelist3------------------------------------------
attr(mtcarsList, "subheadings") <- NULL
xList3 <- xtableList(mtcarsList)
str(xList3)
## ----xtablelist4------------------------------------------
attr(mtcarsList, "message") <- NULL
xList4 <- xtableList(mtcarsList)
str(xList4)
## ----singledefault, results='asis'------------------------
print.xtableList(xList)
## ----singlebooktabs, results='asis'-----------------------
print.xtableList(xList, booktabs = TRUE)
## ----singlebooktabs1, results='asis'----------------------
print.xtableList(xList1, booktabs = TRUE)
## ----sanitize---------------------------------------------
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, '}')
}
## ----sanitizesingle, results='asis'-----------------------
print.xtableList(xList,
sanitize.rownames.function = italic,
sanitize.colnames.function = large,
sanitize.subheadings.function = bold,
sanitize.message.function = red,
booktabs = TRUE)
## ----singlecaption, results='asis'------------------------
print.xtableList(xList2, floating = TRUE)
## ----singlerotated, results='asis'------------------------
print.xtableList(xList, rotate.colnames = TRUE)
## ----nosubheadings, results='asis'------------------------
print.xtableList(xList3)
## ----nomessage, results='asis'----------------------------
print.xtableList(xList4)
## ----multipledefault, results='asis'----------------------
print.xtableList(xList, colnames.format = "multiple")
## ----multiplebooktabs, results='asis'---------------------
print.xtableList(xList, colnames.format = "multiple",
booktabs = TRUE)
## ----sanitizemultiple, results='asis'---------------------
print.xtableList(xList, colnames.format = "multiple",
sanitize.rownames.function = italic,
sanitize.colnames.function = large,
sanitize.subheadings.function = bold,
sanitize.message.function = red,
booktabs = TRUE)
## ----multiplecaption, results='asis'----------------------
print.xtableList(xList2, colnames.format = "multiple",
floating = TRUE)
## ----multiplerotated, results='asis'----------------------
print.xtableList(xList, colnames.format = "multiple",
rotate.colnames = TRUE)
## ----multiplenosubheadings, results='asis'----------------
print.xtableList(xList3, colnames.format = "multiple")
## ----multiplenomessage, results='asis'--------------------
print.xtableList(xList4, colnames.format = "multiple")
|