Debian Codegraph @

inst/doc/pandoc_table.R

raw
1 ## ---- echo = FALSE, message = FALSE-------------------------------------------
2 knitr::opts_chunk$set(collapse = T, comment = "#>")
3 library(pander)
4
5 ## -----------------------------------------------------------------------------
6 m <- data.frame('Value\n1', 'Value\n2')
7 colnames(m) <- c('Multiline\nCol1', 'Multiline\nCol2')
8 pandoc.table(m, keep.line.breaks = TRUE)
9 m <- mtcars[1:3, 1:4]
10 pandoc.table(m)
11
12 ## ---- error=TRUE--------------------------------------------------------------
13 m <- mtcars[1:3, 1:4]
14 pandoc.table(m, style = 'simple')
15 m <- data.frame('Value\n1', 'Value\n2')
16 colnames(m) <- c('Multiline\nCol1', 'Multiline\nCol2')
17 pandoc.table(m, keep.line.breaks = TRUE, style='simple')
18
19 ## ---- error=TRUE--------------------------------------------------------------
20 m <- mtcars[1:3, 1:4]
21 pandoc.table(m, style = 'grid')
22 m <- data.frame('Value\n1', 'Value\n2')
23 colnames(m) <- c('Multiline\nCol1', 'Multiline\nCol2')
24 pandoc.table(m, keep.line.breaks = TRUE, style='grid')
25
26 ## ---- error=TRUE--------------------------------------------------------------
27 m <- mtcars[1:3, 1:4]
28 pandoc.table(m, style = 'rmarkdown')
29 m <- data.frame('Value\n1', 'Value\n2')
30 colnames(m) <- c('Multiline\nCol1', 'Multiline\nCol2')
31 pandoc.table(m, keep.line.breaks = TRUE, style='rmarkdown')
32
33 ## -----------------------------------------------------------------------------
34 pandoc.table(head(iris[,1:3], 2), justify = 'right')
35 pandoc.table(head(iris[,1:3], 2), justify = c('right', 'center', 'left'))
36
37 ## -----------------------------------------------------------------------------
38 set.alignment('left', row.names = 'right') # set only for next table since permanent parameter is falce
39 pandoc.table(mtcars[1:2, 1:5])
40
41 ## -----------------------------------------------------------------------------
42 panderOptions('table.alignment.default',
43 function(df)
44 ifelse(sapply(df, mean) > 2, 'left', 'right'))
45 pandoc.table(head(iris[,1:3], 2))
46 panderOptions('table.alignment.default', 'center')
47
48 ## -----------------------------------------------------------------------------
49 t <- mtcars[1:3, 1:5]
50 emphasize.italics.cols(1)
51 emphasize.italics.rows(1)
52 emphasize.strong.cells(which(t > 20, arr.ind = TRUE))
53 pandoc.table(t)
54 pandoc.table(t, emphasize.verbatim.rows = 1, emphasize.strong.cells = which(t > 20, arr.ind = TRUE))
55
56 ## -----------------------------------------------------------------------------
57 pandoc.table(mtcars[1:2, ], style = "grid", caption = "Wide table to be split!")
58
59 ## -----------------------------------------------------------------------------
60 pandoc.table(mtcars[1:2, ], style = "grid",
61 caption = "Wide table to be split!", split.table = Inf)
62
63 ## ---- error=TRUE--------------------------------------------------------------
64 df <- data.frame(a = 'Lorem ipsum', b = 'dolor sit', c = 'amet')
65 pandoc.table(df, split.cells = 5)
66 pandoc.table(df, split.cells = c(5, 20, 5))
67 pandoc.table(df, split.cells = c("80%", "10%", "10%"))
68 pandoc.table(df, split.cells = 5, style = 'simple')
69
70 ## -----------------------------------------------------------------------------
71 pandoc.table(data.frame(baz = 'foobar', foo='accoutrements'),
72 use.hyphening = TRUE, split.cells = 3)
73
74 ## -----------------------------------------------------------------------------
75 r <- matrix(c(283764.97430, 29.12345678901, -7.1234, -100.1), ncol = 2)
76 pandoc.table(r, round = 2)
77 pandoc.table(r, round = c(4,2)) # vector for each column
78 pandoc.table(r, digits = 2)
79 pandoc.table(r, digits = c(1, 5)) # vector for each column
80 pandoc.table(r, big.mark = ',')
81 pandoc.table(r, decimal.mark = ',')
82
83 ## -----------------------------------------------------------------------------
84 pandoc.table(mtcars[1:3, 1:4])
85 pandoc.table(mtcars[1:3, 1:4], plain.ascii = TRUE)
86
87 ## -----------------------------------------------------------------------------
88 pandoc.table(mtcars[1:3, 1:5], style = "grid", caption = "My caption!")
89
90 ## -----------------------------------------------------------------------------
91 m <- mtcars[1:3, 1:5]
92 m$mpg <- NA
93 pandoc.table(m, missing = '?')
94