Skip to content

Commit bea6e20

Browse files
committed
update examples
1 parent fdb7952 commit bea6e20

File tree

6 files changed

+86
-37
lines changed

6 files changed

+86
-37
lines changed

R/save_as_html.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ save_html_with_rmarkdown <- function(x,
199199
#' id = USUBJID,
200200
#' )
201201
#'
202+
#' # save a gtsummary table as html
203+
#' tbl |>
204+
#' save_html(path = tempfile(fileext = ".html"))
205+
#'
202206
#' # save as html with gt
203207
#' tbl |>
204208
#' gtsummary::as_gt() |>
@@ -212,7 +216,7 @@ save_html_with_rmarkdown <- function(x,
212216
#' css = "body { font-family: Arial; font-size: 12px; }"
213217
#' )
214218
#'
215-
#' # save a paginated table as html
219+
#' # save a paginated table as html — pages are separated by a horizontal rule
216220
#' gtsummary::tbl_split_by_rows(tbl, row_numbers = seq(20, nrow(tbl), by = 20)) |>
217221
#' save_html(path = tempfile(fileext = ".html"))
218222
#'

R/save_as_txt.R

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,15 @@ save_txt_with_rmarkdown <- function(x,
143143
#' `.rmd` file that is rendered.
144144
#'
145145
#' @examples
146-
#' # create gt table
147-
#' tbl <- gt::gt(head(mtcars))
146+
#' # save a gt table as txt
147+
#' gt::gt(head(mtcars)) |>
148+
#' save_txt(path = tempfile(fileext = ".txt"))
148149
#'
149-
#' # save as txt
150-
#' tbl |>
150+
#' # save a gtsummary table as txt
151+
#' gtsummary::tbl_summary(gtsummary::trial[, c("age", "trt")]) |>
151152
#' save_txt(path = tempfile(fileext = ".txt"))
152153
#'
153-
#' # save a list of gt tables as txt
154+
#' # save a list of gt tables as txt — tables are separated by a horizontal rule
154155
#' list(gt::gt(head(mtcars)), gt::gt(tail(mtcars))) |>
155156
#' save_txt(path = tempfile(fileext = ".txt"))
156157
#'

README.Rmd

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@ output: github_document
44

55
<!-- README.md is generated from README.Rmd. Please edit that file -->
66

7-
```{r, include = FALSE}
8-
knitr::opts_chunk$set(
9-
collapse = TRUE,
10-
comment = "#>",
11-
fig.path = "man/figures/README-",
12-
out.width = "100%"
13-
)
14-
```
15-
167
# pager
178

189
<!-- badges: start -->
@@ -22,11 +13,12 @@ knitr::opts_chunk$set(
2213
[![Codecov test coverage](https://codecov.io/gh/insightsengineering/pager/graph/badge.svg)](https://app.codecov.io/gh/insightsengineering/pager)
2314
<!-- badges: end -->
2415

25-
The pager package makes it simple to save tables of class gtsummary, gt, and flextable as a Word document using a reference document.
26-
This is accomplished by creating the document via R markdown using the `reference_docx:` field.
16+
The pager package makes it simple to save tables and plots as Word, HTML, or plain text documents.
17+
Tables of class `gtsummary`, `gt`, and `flextable`, as well as `ggplot` and `grob` plots, are supported.
18+
This is accomplished by rendering the objects via R Markdown.
2719

28-
The package also supports lists of table objects.
29-
When a list is passed, a page break is placed between each table in the list.
20+
The package also supports lists of objects.
21+
When a list is passed, each element is placed on a separate page (Word), separated by a horizontal rule (HTML), or separated by a horizontal rule (plain text).
3022

3123
## Installation
3224

@@ -41,7 +33,7 @@ pak::pak("insightsengineering/pager")
4133

4234
To begin, let's create a summary table.
4335

44-
```{r example}
36+
``` r
4537
library(pager)
4638

4739
# create table
@@ -55,17 +47,59 @@ tbl <-
5547
)
5648
```
5749

58-
The code below will save the table as Word document using the default portrait orientation reference document.
50+
### Word (.docx)
51+
52+
The code below will save the table as a Word document using the default portrait orientation reference document.
5953

60-
```{r table}
54+
``` r
6155
gtsummary::as_flex_table(tbl) |>
62-
save_with_rmarkdown(path = tempfile(fileext = ".docx"))
56+
save_docx(path = tempfile(fileext = ".docx"))
6357
```
6458

6559
The example below first splits the summary table into a list of tables.
6660
Each table is saved to a separate page in the resulting Word document.
6761

68-
```{r table-list}
62+
``` r
6963
gtsummary::tbl_split_by_rows(tbl, row_numbers = seq(20, nrow(tbl), by = 20)) |>
70-
save_with_rmarkdown(path = tempfile(fileext = ".docx"))
64+
save_docx(path = tempfile(fileext = ".docx"))
65+
```
66+
67+
### HTML (.html)
68+
69+
The code below will save the table as a self-contained HTML file.
70+
71+
``` r
72+
tbl |>
73+
gtsummary::as_gt() |>
74+
save_html(path = tempfile(fileext = ".html"))
75+
```
76+
77+
A paginated table can also be saved as HTML — each page is separated by a horizontal rule.
78+
79+
``` r
80+
gtsummary::tbl_split_by_rows(tbl, row_numbers = seq(20, nrow(tbl), by = 20)) |>
81+
save_html(path = tempfile(fileext = ".html"))
82+
```
83+
84+
### Plain text (.txt)
85+
86+
The code below will save the table as a plain text (Markdown-formatted) file.
87+
88+
``` r
89+
tbl |>
90+
save_txt(path = tempfile(fileext = ".txt"))
91+
```
92+
93+
`save_txt()` also accepts `gt` tables directly.
94+
95+
``` r
96+
gt::gt(head(mtcars)) |>
97+
save_txt(path = tempfile(fileext = ".txt"))
98+
```
99+
100+
A list of tables can also be saved as plain text — each table is separated by a horizontal rule.
101+
102+
``` r
103+
list(gt::gt(head(mtcars)), gt::gt(tail(mtcars))) |>
104+
save_txt(path = tempfile(fileext = ".txt"))
71105
```

man/save_html.Rd

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/save_txt.Rd

Lines changed: 13 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/save_txt_with_rmarkdown.Rd

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)