| Type: | Package |
| Title: | Export 'gtsummary' Tables with 'reporter' |
| Version: | 0.1.1 |
| Date: | 2026-06-26 |
| Maintainer: | Xiecheng Gu <guxc0405med@163.com> |
| Description: | Convert 'gtsummary' tables and plain data frames into clinical-style Rich Text Format, plain text, Word, PDF, and HTML outputs using 'reporter', with managed widths, pagination, indentation, spanning headers, and optional intermediate data exports. |
| License: | Apache License 2.0 |
| URL: | https://github.com/openpharma/derrick/ |
| BugReports: | https://github.com/openpharma/derrick/issues |
| Depends: | R (≥ 4.4) |
| Imports: | dplyr, purrr, reporter (≥ 1.4.7), rlang, stringi, tibble |
| Suggests: | cards (≥ 0.8.0), gtsummary (≥ 2.5.1), knitr, rmarkdown, testthat (≥ 3.3.0) |
| Config/Needs/website: | pkgdown |
| VignetteBuilder: | knitr |
| Encoding: | UTF-8 |
| Language: | en-US |
| RoxygenNote: | 7.3.3 |
| NeedsCompilation: | no |
| Packaged: | 2026-07-03 11:03:37 UTC; Kathy Zhang |
| Author: | Xiecheng Gu [aut, cre], Joe Zhu [aut], Bill Huang [aut] |
| Repository: | CRAN |
| Date/Publication: | 2026-07-10 20:30:31 UTC |
Export gtsummary tables with reporter
Description
Convert gtsummary tables and plain data frames into clinical-style
reporter RTF, TXT, DOCX, PDF, and HTML outputs.
Author(s)
Maintainer: Xiecheng Gu guxc0405med@163.com
Authors:
Joe Zhu sha.joe.zhu@gmail.com
Bill Huang Bill.Huang@Toastmasters.org.tw
See Also
Useful links:
Export gtsummary tables to clinical-style reporter outputs
Description
Convert a gtsummary object (or a plain data.frame) into a reporter
table and write RTF, TXT, DOCX, PDF, and/or HTML outputs. The function is
designed for clinical reporting workflows and supports column labels,
spanning headers, pagination, indentation handling, and optional export of
intermediate data.
Usage
gtsummary_reporter(
gts_obj,
file_path,
max_table_width = NULL,
min_col_width = 0.6,
column_widths = NULL,
column_labels = NULL,
spanning_headers = NULL,
report_orientation = "landscape",
report_paper_size = "letter",
report_units = "inches",
report_margins = NULL,
report_font_size = 9,
indent_unit = 1,
output_types = c("RTF", "TXT"),
save_rds = TRUE,
save_ard = FALSE,
rds_dir = "rds",
rows_per_page = NULL,
max_chars_per_line = NULL,
debug_indent = FALSE,
debug_spanning = FALSE,
group_columns = NULL,
group_blank_after = TRUE,
page_by_columns = NULL,
page_by_label = ""
)
Arguments
gts_obj |
A |
file_path |
Required output path. The extension is ignored and output
files are written according to |
max_table_width |
Optional maximum total table width in |
min_col_width |
Minimum width allowed for manually supplied
|
column_widths |
Optional manual column widths in |
column_labels |
Optional column header overrides, as a named vector/list
or a data frame with |
spanning_headers |
Optional spanning header definitions, as a data frame
or list with fields |
report_orientation |
Page orientation ( |
report_paper_size |
Paper size ( |
report_units |
Units for dimensions ( |
report_margins |
Optional margins as named vector/list ( |
report_font_size |
Base report font size. |
indent_unit |
Number of spaces per indent level in |
output_types |
Output types to write; supported values are |
save_rds |
Logical; when |
save_ard |
Logical; when |
rds_dir |
Reserved argument for backward compatibility. |
rows_per_page |
Optional maximum number of table rows per manual chunk.
If |
max_chars_per_line |
Optional integer. For TXT output, constrains the
total table width so that at most this many characters fit across one TXT
line (Courier at 12 CPI). Applied after |
debug_indent |
Logical; print indentation diagnostics. |
debug_spanning |
Logical; print spanning-header diagnostics. |
group_columns |
Optional grouping columns to hide and apply
|
group_blank_after |
Logical; whether to apply |
page_by_columns |
Optional columns to hide and pass to
|
page_by_label |
Prefix label for |
Details
Environment variables are automatically consumed when available:
title1-title9, footnote1-footnote9, and progname.
Widths are resolved in this order:
Compute the usable page width as
page_width - left_margin - right_margin.If
max_table_widthis supplied, cap it at that usable width and pass it toreporter::create_table(). If it isNULL, no table width is passed and reporter calculates the automatic width for each output format.For TXT output only, apply
max_chars_per_lineas an additional character-budget cap (max_chars_per_line / 12inches), when supplied.If
column_widthsis supplied, pass those manual widths to reporter after scaling them down to the effective table width when needed. Ifcolumn_widthsisNULL, no column widths are passed and reporter calculates them from the target format, font, font size, headers, and table contents.
Pagination is delegated to reporter by default. When rows_per_page is
NULL, the table is passed to reporter::write_report() as one table, and
reporter computes page breaks using output-specific fixed metrics plus the
actual wrapped title, header, row, and footnote line counts. Set
rows_per_page only when you need to force manual chunks before reporter's
own pagination runs.
Value
A character vector containing generated output file paths.
Examples
gts_tbl <- gtsummary::trial |>
dplyr::select(trt, age, grade) |>
gtsummary::tbl_summary(by = trt) |>
gtsummary::add_p()
out <- gtsummary_reporter(
gts_obj = gts_tbl,
file_path = tempfile("clinical_report_", fileext = ".rtf"),
output_types = "TXT",
save_rds = FALSE
)
out