1
PharmaSUG 2020 - Paper DV-198
r2rtf – an R Package to Produce Rich Text Format (RTF) Tables and Figures
Siruo Wang, Johns Hopkins Bloomberg School of Public Health, MD, USA;
Simiao Ye, Merck & Co., Inc., Kenilworth, NJ, USA;
Keaven M. Anderson, Merck & Co., Inc., Kenilworth, NJ, USA;
Yilong Zhang, Merck & Co., Inc., Kenilworth, NJ, USA;
ABSTRACT
The use of open-source R is evolving in drug discovery, research and development for study design, data
analysis, visualization, and report generation in the pharmaceutical industry. The ability to produce tables,
listings and figures (TLFs) in customized rich text format (RTF) using R is crucial to enhance the workflow
of using Microsoft Word to assemble analysis results. We developed an R package, r2rtf, that standardizes
the approach to generate highly customized TLFs in RTF format. The r2rtf package provides flexibility to
customize table appearance for table title, subtitle, column header, footnote, and data source. The table
size, border type, color, and line width can be adjusted in each cell as well as column width, row height,
text format, font size, text color, alignment, etc. The control of the format can be row or column vectorized
by leveraging the vectorization in R. Furthermore, r2rtf provides pagination, section grouping, multiple
tables concatenations for complicated table layouts. In this paper, we provide an overview r2rtf workflow
with examples for both required and optional easy-to-use functions. Code examples are provided to create
customized RTF tables and figures with highlighted features. The open-source r2rtf R package is available
at: https://github.com/Merck/r2rtf.
INTRODUCTION
Modern problems in medicine and pharmaceutical settings leverage open-source R to make new
discoveries. While analyses are being conducted in the R platform, it is desirable to generate tables, listings,
and figures (TLFs) in rich text format (RTF) using R. Later these TLFs can be directly inserted into a word
document for the final analyses report generation. The ability to produce TLFs in customized RTF files
using R is crucial to enhance the workflow of using Microsoft Word to assemble analysis results.
Although many tools and macros have been developed in SAS
®
programs over the past decades to
generate RTF tables such as %SASWORD1 (Cunningham 1998), %SAS2WORD (Zhou 2001), %PRINT
(Wehr 1996), %RTF (Peszek et al. 1998 and 1999), and particularly macro %RTFTable (Qi et al. 2003) and
proc report in SAS
®
that is very rich in functionality, there are only a few packages available to convert
datasets to RTF tables with flexibilities in the R platform. The two existing R packages, rtf (Schaffer 2019)
and gt (Iannone et al. 2020), currently provide limited ability to produce TLFs in RTF files for clinical
reporting. The rtf package depends on two other R packages and provides 18 functions to handle different
parts of the process. To generate TLFs, users are required to be familiar with the concept of RTF syntax
with multiple functions such as start a paragraph, end a paragraph, add new lines, add a table, add text,
set font size, etc. The gt package provides more flexibility to change table and figure appearance and
present them in HTML, PDF and RTF. The gt package also depends on 14 other R packages and uses a
large numbr of functions for detailed feature controls. Currently, the gt package is under active development
and focuses on HTML format. Its ability to generate RTF tables is still under development.
Therefore, we are motivated to develop a new package, r2rtf, that provides easy-to-use and powerful
functions to convert datasets into highly customized TLFs in RTF file using R. We carefully reduce the
package dependency to simplify the qualification of the package for regulatory purpose. The only
dependency of our r2rtf package is stringr (Wickham 2019) that is used for displaying special characters
and symbols in latex code for the r2rtf package. The design of r2rtf is to reduce the efforts from users to set
a large number of features for table formatting by given commonly used default settings (e.g., border type,
color, line width, etc.). Compared to the existing rtf and gt packages, less dependency of other R packages
makes r2rtf easy to install and ready for regulatory use.
Our package also minimizes the number of functions needed to generate TLFs which significantly enhances
the workflow to generate TLFs in RTF files and reduce the user’s input efforts. In detail, r2rtf provides three