| Title: | Export 'gtsummary' Tables with 'reporter' |
|---|---|
| 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. |
| Authors: | Xiecheng Gu [aut, cre], Joe Zhu [aut], Bill Huang [aut] |
| Maintainer: | Xiecheng Gu <[email protected]> |
| License: | Apache License 2.0 |
| Version: | 0.1.1 |
| Built: | 2026-07-10 22:46:49 UTC |
| Source: | https://github.com/cran/derrick |
Convert gtsummary tables and plain data frames into clinical-style
reporter RTF, TXT, DOCX, PDF, and HTML outputs.
Maintainer: Xiecheng Gu [email protected]
Authors:
Joe Zhu [email protected]
Bill Huang [email protected]
Useful links:
gtsummary tables to clinical-style reporter outputsConvert 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.
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 = "" )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 = "" )
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 |
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_width is supplied, cap it at that usable width and pass it
to reporter::create_table(). If it is NULL, no table width is passed
and reporter calculates the automatic width for each output format.
For TXT output only, apply max_chars_per_line as an additional
character-budget cap (max_chars_per_line / 12 inches), when supplied.
If column_widths is supplied, pass those manual widths to reporter after
scaling them down to the effective table width when needed. If
column_widths is NULL, 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.
A character vector containing generated output file paths.
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 ) outgts_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