Chapter 2 Overview of table R packages

There are many R packages available that can help with the creation of production-ready tables for clinical research. We provide here a listing of the most notable packages available for this purpose. The descriptions are meant to provide a basic overview of what each package is capable of, and, the general focus area for each. Word of warning: the list is by no means complete. There are possibly dozens of such packages, but we were selective in choosing which of those to present here (mostly in the interest of not presenting too much material, so as to not burden the reader with too many alternatives).

2.1 gt

The gt package (Iannone et al. 2024, website) provides a high-level and declarative interface for composing tables. The package contains a large variety of formatting functions for transforming cell values from an input data frame to the desired reporting values. There are options for scientific notation, percentages, localized currencies, expressing uncertainties and ranges, dates and times, etc.). The package has the ability to generate summary rows, footnotes, source notes, and structure the table with a stub and column spanners. Multiple output formats are supported with the same declarative interface (e.g., HTML, LaTeX/PDF, RTF, and Word).

The gt source code is on GitHub and the project website provides a wealth of documentation. The package is also available on CRAN.

2.2 rtables

The rtables package (Becker and Waddell 2024, website) defines a pipe-able grammar for declaring complex table structure layouts via nested splitting – in row- and column-space – and the specification of analysis functions which will calculate cell values within that structure. These pre-data table layouts are then applied to data to build the table, during which all necessary data grouping implied by the row and column splits, cell value calculation, and tabulation occurs automatically. Additional table features such as titles, footers, and referential footnotes are supported. ASCII, HTML, and PDF are supported as output formats for rendering tables.

The rtables package is available on CRAN. Its source code GitHub and documentation are also available on Github, where development of the package occurs.

rtables is also the table engine used (as wrapped by tern) in the open source TLG Catalog.

2.3 tern (+ rtables)

The tern package (Zhu et al. 2024, website) is an open sourced, opinionated TLG generation package for clinical trials. With respect to tables, tern acts as wrapper around the core rtables tabulation engine which performs two functions with respect to standard tables clinical trial tables: implementation of statistical logic, and providing convenience wrappers for common table layout patterns. In particular, tern implements and open-sources the statistical choices used by Roche ™ when constructing clinical trial tables.

The open source TLG Catalog uses tern and rtables to implement over 220 stanard clinical trial table variants across 8 table categories. The catalog includes open source-permissively licensed, runnable code for each entry.

The tern package is available on CRAN. Its source code GitHub and documentation are also available on Github, where development of the package occurs.

2.4 flextable

flextable (Gohel and Skintzos 2024, website) provides a grammar for creating and customizing tables. The following formats are supported: ‘Word’ (.docx), ‘PowerPoint’ (.pptx), ‘RTF’, ‘PDF’ ,‘HTML’ and R ‘Grid Graphics’. The syntax is the same for the user regardless of the type of output to be produced. A set of functions allows the creation, definition of cell arrangement, addition of headers or footers, formatting and definition of cell content (i.e. text and or images). The package also offers a set of high-level functions that allow, for example, tabular reporting of statistical models and the creation of complex cross tabulations.

Source code is on GitHub and a user manual is available. The package is also available on CRAN.

2.5 tfrmt

The tfrmt (Krouse et al. 2024, website) package provides a language for defining display-related metadata and table formatting before any data is available. This package offers an intuitive interface for defining and layering standard or custom formats, to which ARD (analysis results data) is supplied. It also presents the novel ability to easily generate mock displays using metadata that will be used for the actual displays. tfrmt is built on top of the gt package, which is intended to support a variety of output formats in the future. Table features (titles, header, footnotes, etc.) as well as specific formatting (e.g. rounding, scientific notation, alignment, spacing) are supported.

The tfrmt source code is on GitHub and documentation can be found in the project website. The package is also available on CRAN.

2.6 tables

The tables package (Murdoch 2024, website) provides a formula-driven interface for computing the contents of tables and formatting them. It was inspired by SAS PROC TABULATE, but is not compatible with it.

The user computes a table object by specifying a formula, with the left-hand side giving the rows, and the right-hand side giving the columns; the formula describes the summary functions to apply and how to organize them. The objects can be subsetted or combined using matrix-like operations. Tables can be rendered in plain text, LaTeX code to appear in a PDF document, or HTML code for a web document.

The package is on CRAN. Source is maintained on Github at https://github.com/dmurdoch/tables/. Vignettes in the package serve as a user manual; browse them at https://dmurdoch.github.io/tables/, or install the package, then run browseVignettes(package = "tables").

2.7 tidytlg

The tidytlg package (Masel et al. 2024, website) provides a framework for creating tables, listings, and graphs (TLGs) using Tidyverse (Wickham et al. 2019). It offers a suite of analysis functions to summarize descriptive statistics (univariate statistics and counts or percentages) for table creation and a function to convert analysis results to rtf/html outputs. For graphic output, tidytlg can integrate plot objects created by ggplot2 or a png file with titles and footnotes to produce rtf/html output.

tidytlg source code and documentation are on Github.

References

Becker, Gabriel, and Adrian Waddell. 2024. Rtables: Reporting Tables. R package version 0.6.9. https://github.com/insightsengineering/rtables.
Gohel, David, and Panagiotis Skintzos. 2024. Flextable: Functions for Tabular Reporting. R package version 0.9.6. https://ardata-fr.github.io/flextable-book/.
Iannone, Richard, Joe Cheng, Barret Schloerke, Ellis Hughes, Alexandra Lauer, and JooYoung Seo. 2024. Gt: Easily Create Presentation-Ready Display Tables. R package version 0.10.1. https://gt.rstudio.com.
Krouse, Becca, Christina Fillmore, Ellis Hughes, Karima Ahmad, and Shannon Haughton. 2024. Tfrmt: Applies Display Metadata to Analysis Results Datasets. R package version 0.1.1.0999, commit 7c70d2b1aab50eb8aa418fc4888b8927464dfd3a. https://github.com/GSK-Biostatistics/tfrmt.
Masel, Nicholas, Steven Haesendonckx, Pelagia Alexandra Papadopoulou, Sheng-Wei Wang, Eli Miller, Nathan Kosiba, Aidan Ceney, and Konrad Pagacz. 2024. Tidytlg: Create TLGs Using the Tidyverse. R package version 0.1.5. https://pharmaverse.github.io/tidytlg/main/.
Murdoch, Duncan. 2024. Tables: Formula-Driven Table Generation. R package version 0.9.28. https://dmurdoch.github.io/tables/.
Wickham, Hadley, Mara Averick, Jennifer Bryan, Winston Chang, Lucy D’Agostino McGowan, Romain François, Garrett Grolemund, et al. 2019. “Welcome to the tidyverse.” Journal of Open Source Software 4 (43): 1686. https://doi.org/10.21105/joss.01686.
Zhu, Joe, Daniel Sabanés Bové, Jana Stoilova, Davide Garolini, Emily de la Rua, Abinaya Yogasekaram, Heng Wang, et al. 2024. Tern: Create Common TLGs Used in Clinical Trials. R package version 0.9.5. https://insightsengineering.github.io/tern/.