Docorate (Decorate + Output) Displays

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.


docorator docorator logo

R-CMD-check status:experimental

{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()

Installation

The {docorator} package can be installed from CRAN with:

install.packages("docorator")

The development version of {docorator} can be installed with:

devtools::install_github("GSK-Biostatistics/docorator")

Use

# 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()
Docorator example

Note

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

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("docorator")

0.7.0 by Shannon Haughton, 3 months ago


https://GSK-Biostatistics.github.io/docorator/, https://github.com/GSK-Biostatistics/docorator


Report a bug at https://github.com/GSK-Biostatistics/docorator/issues


Browse source code at https://github.com/cran/docorator


Authors: Shannon Haughton [aut, cre] , Becca Krouse [aut] , Seongbin Hong [aut] , Dragoș Moldovan-Grünfeld [aut] , GlaxoSmithKline Research & Development Limited [cph, fnd]


Documentation:   PDF Manual  


Apache License 2.0 license


Imports gt, rmarkdown, rlang, cli, dplyr, rstudioapi, purrr, stringr, stringi, tidyr, lifecycle, png, knitr, withr, quarto, officer, polish, xml2

Suggests rprojroot, testthat, tfrmt, pdftools, ggplot2


See at CRAN