Learn R Programming

docorator

{docorator} is an engine for creating production displays from R. Specifically, {docorator} provides the following functionality:

  • Decorate: Surround displays with document-level headers, footers, and page numbers
  • Output: Export decorated displays to a file such as PDF or RTF

The main function, as_docorator() accepts an R object containing the display as input. For best results with sizing, the table should be prepared via {gt}, or packages that interface with {gt} such as {tfrmt}, and the figure should be prepared with {ggplot2}. Alternatively, the path to a PNG can be passed to {docorator}. Specifically, the x should be one of the following:

  • gt table
  • gt_group (list of gt tables)
  • ggplot2 figure
  • list of ggplot figures
  • path to PNG file (i.e. a previously created figure)
  • list of paths to PNG files

The docorator object, which is saved by default, can then be output using one or both of the following render functions which can be piped together: render_pdf() and render_rtf()

Use

# install from GitHub
devtools::install_github("GSK-Biostatistics/docorator")

# Load package
library(docorator) 

# Create table (or figure)
mytbl <- gt::exibble |> 
  gt::gt()

# Export display   
mytbl |> 
  as_docorator( 
    display_name = "mytbl",
    header = fancyhead(
      fancyrow(left = "My Study", center = NA, right = doc_pagenum()),
      fancyrow(left = "My Population", center = NA, right = NA),
      fancyrow(left = NA, center = "My Table", right = NA)
    ),
    footer = fancyfoot(
      fancyrow(left = "mypath/mytbl.R", center = NA, right = "Data as of 2025-01-01")
    ) 
  ) |> 
  render_pdf() |>
  render_rtf()

Note

{docorator} requires LaTeX libraries for PDF rendering. If using {tinytex}, the “TinyTeX” bundle covers the core dependencies.

Copy Link

Version

Install

install.packages('docorator')

Monthly Downloads

468

Version

0.5.2

License

Apache License 2.0

Issues

Pull Requests

Stars

Forks

Maintainer

Becca Krouse

Last Published

January 23rd, 2026

Functions in docorator (0.5.2)

create_chunk

Create prep_obj_tex code chunks Taken from https://gist.github.com/MichaelJW/b4a3dd999a47b137d12f42a8f7562b11
as_docorator

Create docorator object
doc_datetime

Date and time of program run
doc_pagenum

Automatic page numbering
apply_to_gt_group

apply a gt function to a gt_group
doc_path

Path of program
fancyfoot

Construct document footer
docorate

Decorate and output a table, listing, or figure to a file
fancyhead

Construct document header
fancyrow

Construct document header row
png_path

Path of png file
geom_set

Set document geometry defaults
scale_gt

Scale gt table contents for document
render_rtf

Render to rtf
render_pdf

Render to pdf
check_pkg_version

Check package versions for docorator object are the same as loaded
hf_extract

extract header footer info from docorator object
prep_obj_tex

Prepare table, listing, figure object for inclusion in the template Rmd
hf_process

Process headers/footers
prep_obj_rtf

Prepare table, listing, figure object for output to rtf
apply_scale

Apply scaling to gt objects
hf_to_gt

Apply headers and footnotes to gt object
hf_height

Calculate desired header or footer height for the document