Title: | Docorate (Decorate + Output) Displays |
Version: | 0.5.0 |
Description: | A framework for creating production outputs. Users can frame a table, listing, or figure with headers and footers and save to an output file. Stores an intermediate 'docorator' object for reproducibility and rendering to multiple output types. |
License: | Apache License 2.0 |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
Imports: | gt (≥ 0.11.0), rmarkdown, rlang, cli, dplyr, rstudioapi, purrr, stringr, tidyr, lifecycle, png, knitr, withr, quarto |
Suggests: | rprojroot, testthat (≥ 3.0.0), tfrmt, pdftools, ggplot2 |
Config/testthat/edition: | 3 |
VignetteBuilder: | knitr |
URL: | https://GSK-Biostatistics.github.io/docorator/, https://github.com/GSK-Biostatistics/docorator |
BugReports: | https://github.com/GSK-Biostatistics/docorator/issues |
Depends: | R (≥ 4.1.0) |
NeedsCompilation: | no |
Packaged: | 2025-09-22 15:38:15 UTC; bkrouse |
Author: | Becca Krouse [aut, cre], Shannon Haughton [aut], Seongbin Hong [aut], Dragoș Moldovan-Grünfeld [aut], GlaxoSmithKline Research & Development Limited [cph, fnd] |
Maintainer: | Becca Krouse <becca.z.krouse@gsk.com> |
Repository: | CRAN |
Date/Publication: | 2025-09-30 07:10:02 UTC |
Apply scaling to gt objects
Description
Apply scaling to gt objects
Usage
apply_scale(x, fontsize, tbl_scale, tbl_stub_pct)
## Default S3 method:
apply_scale(x, fontsize, tbl_scale, tbl_stub_pct)
## S3 method for class 'gt_tbl'
apply_scale(x, fontsize, tbl_scale, tbl_stub_pct)
## S3 method for class 'gt_group'
apply_scale(x, fontsize, tbl_scale, tbl_stub_pct)
Arguments
x |
gt object |
fontsize |
document font size |
tbl_scale |
Boolean for whether or not to automatically scale table columns to fit display area. Defaults to TRUE. Note that this will overwrite scaling set in the table directly unless set to FALSE. |
tbl_stub_pct |
percent of total width that should be dedicated to stub column(s). If more than 1 stub column then this is the total for both. |
Value
scaled gt object
Examples
gt <- gt::exibble |>
gt::gt()
apply_scale(gt, fontsize = 10, tbl_scale = FALSE, tbl_stub_pct = "20%")
Create docorator object
Description
Create docorator object
Usage
as_docorator(
x,
display_name,
display_loc = NULL,
header = fancyhead(fancyrow(right = doc_pagenum())),
footer = fancyfoot(fancyrow(left = doc_path(display_name, display_loc), right =
doc_datetime())),
save_object = TRUE,
object_loc = display_loc,
...,
fontsize = 10,
geometry = geom_set(),
fig_dim = c(5, 8),
tbl_scale = TRUE,
tbl_stub_pct = 0.3
)
Arguments
x |
object containing the display. See @details for more information. |
display_name |
required name of file (excluding extension) |
display_loc |
optional path to save the output file to |
header |
Document header. Accepts a |
footer |
Document footer Accepts a |
save_object |
Boolean indicating if a docorator object should be saved. |
object_loc |
path for the docorator object - defaults to display_loc argument. |
... |
These dots are for future extensions and must be empty. |
fontsize |
Font size (pt). Defaults to |
geometry |
Document sizing options based on the |
fig_dim |
vector containing figure height and width in inches. Defaults
to |
tbl_scale |
Boolean for whether or not to automatically scale table columns to fit display area. Defaults to TRUE. Note that this will overwrite scaling set in the table directly unless set to FALSE. |
tbl_stub_pct |
percent of total width that should be dedicated to stub column(s). If more than 1 stub column then this is the total for both. |
Details
While the x
argument flexibly accepts many different R objects, the
following classes/types are recommended:
-
gt
-
gt_group
(list ofgt
objects) -
ggplot
list of
ggplot
spath to PNG file created via
png_path()
list of paths to PNG files created via
png_path()
Value
docorator object
Examples
## Not run:
gt::gtcars |>
dplyr::slice_head(n = 10) |>
dplyr::select(mfr, model, year, msrp) |>
gt::gt(groupname_col = "mfr",
row_group_as_column = TRUE) |>
as_docorator(
header = fancyhead(fancyrow("Header 1"), fancyrow("Header 2")),
display_name = "mytbl",
footer = NULL)
## End(Not run)
Create prep_obj_tex code chunks Taken from https://gist.github.com/MichaelJW/b4a3dd999a47b137d12f42a8f7562b11
Description
Create prep_obj_tex code chunks Taken from https://gist.github.com/MichaelJW/b4a3dd999a47b137d12f42a8f7562b11
Usage
create_chunk(x, transform)
Arguments
x |
docorator object |
transform |
optional latex transformation function to apply to a gt latex string |
Value
printed code chunk to be included as-is in the render engine
Examples
## Not run:
docorator <- gt::exibble |>
gt::gt() |>
as_docorator(save_object = FALSE)
create_chunk(docorator, transform = NULL)
## End(Not run)
Date and time of program run
Description
Date and time of program run
Usage
doc_datetime()
Value
character string
Examples
doc_datetime()
Automatic page numbering
Description
Automatic page numbering
Usage
doc_pagenum()
Value
character string containing latex code
Examples
doc_pagenum()
Path of program
Description
Path of program
Usage
doc_path(filename = NULL, path = NULL)
Arguments
filename |
Name of output file |
path |
program path |
Value
character string
Examples
doc_path(filename = "my_tbl.pdf", path = NULL)
Decorate and output a table, listing, or figure to a file
Description
This function was deprecated and replaced with as_docorator
and a corresponding render function
i.e render_pdf
Usage
docorate(
x,
filename,
path = NULL,
header = fancyhead(fancyrow(right = doc_pagenum())),
footer = fancyfoot(fancyrow(left = doc_path(filename, path), right = doc_datetime())),
...,
fontsize = 10,
geometry = geom_set(),
fig_dim = c(5, 8),
tbl_scale = TRUE,
tbl_stub_pct = 0.3
)
Arguments
x |
object containing the display. See @details for more information. |
filename |
required name of file including extension (note: only PDF supported currently) |
path |
optional path to save the output pdf to |
header |
Document header. Accepts a |
footer |
Document footer Accepts a |
... |
These dots are for future extensions and must be empty. |
fontsize |
Font size (pt). Defaults to |
geometry |
Document sizing options based on the |
fig_dim |
vector containing figure height and width in inches. Defaults
to |
tbl_scale |
Boolean for whether or not to automatically scale table columns to fit display area. Defaults to TRUE. Note that this will overwrite scaling set in the table directly unless set to FALSE. |
tbl_stub_pct |
percent of total width that should be dedicated to stub column(s). If more than 1 stub column then this is the total for both. |
Details
While the x
argument flexibly accepts many different R objects, the
following classes/types are recommended:
-
gt
-
gt_group
(list ofgt
objects) -
ggplot
list of
ggplot
spath to PNG file created via
png_path()
list of paths to PNG files created via
png_path()
Value
This function is called for its side effects
Examples
## Not run:
gt::gtcars |>
dplyr::slice_head(n = 10) |>
dplyr::select(mfr, model, year, msrp) |>
gt::gt(groupname_col = "mfr",
row_group_as_column = TRUE) |>
docorate(
header = fancyhead(fancyrow("Header 1"), fancyrow("Header 2")),
filename = "mytbl.pdf")
## End(Not run)
Construct document footer
Description
Define document footer through a series of fancyrow
s. Each row represents
a new line in the footer with options for positioning text at left, center,
and/or right positions.
Usage
fancyfoot(...)
Arguments
... |
Series of objects of class |
Value
Character string containing latex code for the fancyfoot
entries as
part of the fancyhdr
latex framework
Examples
fancyfoot(
fancyrow(left = "My first footnote", right = doc_datetime())
)
Construct document header
Description
Define document header through a series of fancyrow
s. Each row represents
a new line in the header with options for positioning text at left, center,
and/or right positions.
Usage
fancyhead(...)
Arguments
... |
Series of objects of class |
Value
Character string containing latex code for the fancyhead
entries as
part of the fancyhdr
latex framework
Examples
fancyhead(
fancyrow(left = "Protocol: 12345", right = doc_pagenum()),
fancyrow(center = "Demographic Summary")
)
Construct document header row
Description
Define a single row in the document header/footer. Each row represents a single line of text, with options for positioning text at left, center, and/or right.
Usage
fancyrow(left = NA, center = NA, right = NA)
Arguments
left |
Character string to be aligned to the left side of the row. |
center |
Character string to be aligned to the center of the row. |
right |
Character string to be aligned to the right side of the row. |
Value
Object of class fancyrow
Examples
fancyrow(left = "Left most text", right = "Right most text")
fancyrow(center = "Just text in the center")
fancyrow(left = "All", center = "Three", right = "Positions filled")
Set document geometry defaults
Description
Set document geometry defaults
Usage
geom_set(...)
Arguments
... |
Series of named value pairs for latex geometry options |
Details
Type geom_set() in console to view package defaults. Use of the
function will add to the defaults and/or override included defaults of the
same name. For values that are NULL
, such as for headheight
and
footskip
, the values will be calculated automatically based on the number
of header and/or footer lines. For all geometry settings, reference the
documentation here: https://texdoc.org/serve/geometry.pdf/0
Value
Named list
Examples
# view defaults
geom_set()
# Update the defaults
geom_set(left="0.5in", right="0.5in")
# add new defaults
geom_set(paper = "legalpaper")
extract header footer info from docorator object
Description
extract header footer info from docorator object
Usage
hf_extract(x)
Arguments
x |
a docorator object |
Value
list of header footer info
Examples
docorator <- gt::exibble |>
gt::gt()|>
as_docorator(
display_name = "mytbl",
header = fancyhead(
fancyrow(left = "Protocol: 12345", right = doc_pagenum()),
fancyrow(center = "Demographic Summary")
),
footer = NULL,
save_object = FALSE)
hf_extract(docorator)
Calculate desired header or footer height for the document
Description
Calculate desired header or footer height for the document
Usage
hf_height(x, fontsize)
## Default S3 method:
hf_height(x, fontsize)
## S3 method for class 'fancyhdr'
hf_height(x, fontsize)
Arguments
x |
header or footer |
fontsize |
Document font size (pt) |
Value
Numeric value
Examples
header <- fancyhead(
fancyrow(left = "Protocol: 12345", right = doc_pagenum()),
fancyrow(center = "Demographic Summary"))
hf_height(header, 10)
Process headers/footers
Description
Process headers/footers
Usage
hf_process(x, escape_latex = TRUE)
## Default S3 method:
hf_process(x, escape_latex = TRUE)
## S3 method for class 'character'
hf_process(x, escape_latex = TRUE)
## S3 method for class 'fancyhead'
hf_process(x, escape_latex = TRUE)
## S3 method for class 'fancyfoot'
hf_process(x, escape_latex = TRUE)
Arguments
x |
header or footer |
escape_latex |
Boolean to escape latex in header/footer |
Value
character string containing headers and footers latex code
Examples
header <- fancyhead(
fancyrow(left = "Protocol: 12345", right = doc_pagenum()),
fancyrow(center = "Demographic Summary"))
hf_process(header)
Apply headers and footnotes to gt object
Description
Pulls headers and footnotes from the docorator object and applies them to the gt object Note: this function is only for use by downstream tools and is not intended for general users
Usage
hf_to_gt(x)
Arguments
x |
a docorator object |
Value
gt object (either tbl or group)
Examples
docorator <- gt::exibble |>
gt::gt()|>
as_docorator(
display_name = "my_tbl",
header = fancyhead(
fancyrow(left = "Protocol: 12345", right = doc_pagenum()),
fancyrow(center = "Demographic Summary")
),
footer = NULL,
save_object = FALSE)
hf_to_gt(docorator)
Path of png file
Description
Path of png file
Usage
png_path(path = NULL)
Arguments
path |
path to png |
Value
object with png attribute
Examples
## Not run:
png_path <- png_path(path = "path_to_my_png.png")
## End(Not run)
Prepare table, listing, figure object for output to rtf
Description
Prepare table, listing, figure object for output to rtf
Usage
prep_obj_rtf(x, ...)
## Default S3 method:
prep_obj_rtf(x, ...)
## S3 method for class 'character'
prep_obj_rtf(x, ...)
## S3 method for class 'PNG'
prep_obj_rtf(x, ...)
## S3 method for class 'ggplot'
prep_obj_rtf(x, ...)
## S3 method for class 'gt_tbl'
prep_obj_rtf(x, ...)
## S3 method for class 'gt_group'
prep_obj_rtf(x, ...)
## S3 method for class 'list'
prep_obj_rtf(x, ...)
Arguments
x |
docorator object containing display information |
... |
additional args |
Value
gt object to be included as-is to render engine
Examples
docorator <- gt::exibble |>
gt::gt() |>
as_docorator(
display_name = "my_tbl",
footer=NULL,
save_object = FALSE)
prepared_obj <- prep_obj_rtf(docorator)
Prepare table, listing, figure object for inclusion in the template Rmd
Description
Prepare table, listing, figure object for inclusion in the template Rmd
Usage
prep_obj_tex(x, transform = NULL, ...)
## Default S3 method:
prep_obj_tex(x, transform = NULL, ...)
## S3 method for class 'character'
prep_obj_tex(x, transform = NULL, ...)
## S3 method for class 'PNG'
prep_obj_tex(x, transform = NULL, ...)
## S3 method for class 'gt_tbl'
prep_obj_tex(x, transform = NULL, ...)
## S3 method for class 'gt_group'
prep_obj_tex(x, transform = NULL, ...)
Arguments
x |
docorator object containing info about the table, listing or figure |
transform |
optional latex transformation function to apply to a gt latex string |
... |
additional args |
Value
object to be included as-is in render engine
Examples
docorator <- gt::exibble |>
gt::gt() |>
as_docorator(
display_name = "mytbl", footer = NULL,
save_object = FALSE)
prepared_obj <- prep_obj_tex(docorator)
Render to pdf
Description
Render to pdf
Usage
render_pdf(
x,
display_loc = NULL,
transform = NULL,
header_latex = NULL,
keep_tex = FALSE,
escape_latex = TRUE,
quarto = FALSE
)
Arguments
Value
This function saves a pdf to a specified location
Examples
gt::gtcars |> dplyr::slice_head(n = 10) |> dplyr::select(mfr, model, year, msrp) |> gt::gt(groupname_col = "mfr", row_group_as_column = TRUE) |> as_docorator( header = fancyhead(fancyrow("Header 1"), fancyrow("Header 2")), display_name = "mytbl") |> render_pdf()
Render to rtf
Description
Usage
render_rtf(
x,
display_loc = NULL,
remove_unicode_ws = TRUE,
use_page_header = FALSE
)
Arguments
x |
|
display_loc |
path to save the output rtf to |
remove_unicode_ws |
Option to remove unicode white space from text. |
use_page_header |
If |
Details
Option remove_unicode_ws
serves as a workaround for this
issue in gt
Value
This function saves an rtf to a specified location
Examples
gt::gtcars |> dplyr::slice_head(n = 10) |> dplyr::select(mfr, model, year, msrp) |> gt::gt(groupname_col = "mfr", row_group_as_column = TRUE) |> as_docorator( header = fancyhead(fancyrow("Header 1"), fancyrow("Header 2")), display_name = "mytbl") |> render_rtf()
Scale gt table contents for document
Description
Scale gt table contents for document
Usage
scale_gt(x, tbl_stub_pct = 0.3)
Arguments
x |
table of class |
tbl_stub_pct |
percent of total width that should be dedicated to stub column(s). If more than 1 stub column then this is the total for both. |
Value
Table with col_widths settings applied
Examples
gt::gtcars |>
dplyr::slice_head(n = 10) |>
dplyr::select(mfr, model, year, msrp, ctry_origin) |>
gt::gt(
groupname_col = "ctry_origin",
rowname_col = "mfr",
row_group_as_column = TRUE) |>
scale_gt(tbl_stub_pct = 0.4)