-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreporter-wrap.Rmd
64 lines (51 loc) · 1.8 KB
/
reporter-wrap.Rmd
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
---
title: "Example 6: Page Wrap"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Example 6: Page Wrap}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
### Handle Wide Tables with Page Wrap
Page wrapping will occur
automatically if the table width exceeds the available page width. But
page wrapping can also be controlled using the `page_wrap` parameter on the
`define()` function. Below is an example. Also note the use of the `id_var`
option to cause the vehicle column to be retained on each wrapped page.
```{r eval=FALSE, echo=TRUE}
library(reporter)
# Create temp file name
tmp <- file.path(tempdir(), "example6.pdf")
# Prepare data
dat <- mtcars[1:10, ]
dat <- data.frame(vehicle = rownames(dat), dat)
# Define table
tbl <- create_table(dat, show_cols = 1:8) %>%
define(vehicle, label = "Vehicle", width = 3, id_var = TRUE, align = "left") %>%
define(mpg, label = "Miles per Gallon", width = 1) %>%
define(cyl, label = "Cylinders", format = "%.1f") %>%
define(disp, label = "Displacement") %>%
define(hp, label = "Horsepower", page_wrap = TRUE) %>%
define(drat, visible = FALSE) %>%
define(wt, label = "Weight") %>%
define(qsec, label = "Quarter Mile Time", width = 1.5)
# Create the report
rpt <- create_report(tmp, output_type = "PDF",
font = "Courier", font_size = 12) %>%
titles("Listing 2.0", "MTCARS Data Listing with Page Wrap") %>%
set_margins(top = 1, bottom = 1) %>%
add_content(tbl) %>%
page_footer(right = "Page [pg] of [tpg]")
# Write the report
write_report(rpt)
# file.show(tmp)
```
<img src="../man/images/e6a.png"/>
<img src="../man/images/e6b.png"/>
Next: [Example 7: Page By](reporter-pageby.html)