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).
The gt package (Iannone et al. 2023, 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 rtables package (Becker and Waddell 2023, 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.
rtables is also the table engine used (as wrapped by tern) in the open source TLG Catalog.
The tern package (Zhu et al. 2023, 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.
flextable (Gohel and Skintzos 2023, 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.
The tfrmt (Krouse et al. 2023, 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 tables package (Murdoch 2023, website) provides a formula-driven interface for
computing the contents of tables and formatting them. It was
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").
The tidytlg package (Masel et al. 2023, 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.