r2rtf

CRAN status Codecov test coverage CRAN Downloads R-CMD-check status

knitr::opts_chunk$set(echo = TRUE)
pkgname <- "r2rtf"

Overview

r2rtf is an R package to create production-ready tables and figures in RTF format. The package is designed with these principles:

The R for clinical study reports and submission book provides tutorials by using real world examples.

Installation

You can install the package via CRAN:

install.packages("r2rtf")

Or, install from GitHub:

remotes::install_github("Merck/r2rtf")

Highlighted features

The R package r2rtf provides flexibility to enable features below:

Simple example

library(dplyr)
library(r2rtf)

head(iris) %>%
  rtf_body() %>% # Step 1 Add attributes
  rtf_encode() %>% # Step 2 Convert attributes to RTF encode
  write_rtf(file = "ex-tbl.rtf") # Step 3 Write to a .rtf file
library(r2rtf)
try(
  {
    pdftools::pdf_convert("vignettes/pdf/ex-tbl.pdf", dpi = 200, filenames = "ex-tbl.png")
    pdftools::pdf_convert("vignettes/pdf/efficacy_example.pdf", dpi = 200, filenames = "efficacy_example.png")
    pdftools::pdf_convert("vignettes/pdf/ae_example.pdf", dpi = 200, filenames = "ae_example.png")
    files <- c("ex-tbl.png", "efficacy_example.png", "ae_example.png")
    file.copy(from = files, to = file.path("vignettes/fig", files), overwrite = TRUE)
    file.remove(files)
  },
  silent = TRUE
)

Click here to see the output

Example efficacy table

Click here to see the output

Example safety table

Click here to see the output

# Transfer all RTF files to PDF files
files <- list.files("vignettes/rtf", pattern = "*.rtf", full.names = TRUE)

r2rtf:::rtf_convert_format(
  input = files,
  format = "pdf",
  output_dir = "vignettes/pdf"
)

r2rtf:::rtf_convert_format(
  input = files,
  format = "docx",
  output_dir = "vignettes/docx"
)

r2rtf:::rtf_convert_format(
  input = files,
  format = "html",
  output_dir = "vignettes/html"
)

files <- list.files("vignettes/rtf", pattern = "*\\.rtf")
files_pdf <- list.files("vignettes/pdf", pattern = "*\\.pdf")
files_docx <- list.files("vignettes/docx", pattern = "*\\.docx")
files_html <- list.files("vignettes/html", pattern = "*\\.html")

# Compare RTF and PDF folder filenames.
waldo::compare(
  tools::file_path_sans_ext(files),
  tools::file_path_sans_ext(files_pdf)
)

waldo::compare(
  tools::file_path_sans_ext(files),
  tools::file_path_sans_ext(files_docx)
)

waldo::compare(
  tools::file_path_sans_ext(files),
  tools::file_path_sans_ext(files_html)
)

Citation

If you use this software, please cite it as below.

Wang, S., Ye, S., Anderson, K., & Zhang, Y. (2020). r2rtf---an R Package to Produce Rich Text Format (RTF) Tables and Figures. PharmaSUG. https://www.pharmasug.org/proceedings/2020/DV/PharmaSUG-2020-DV-198.pdf

A BibTeX entry for LaTeX users is

@inproceedings{wang2020r2rtf,
  title     = {{r2rtf}---an {R} Package to Produce {Rich Text Format} ({RTF}) Tables and Figures},
  author    = {Wang, Siruo and Ye, Simiao and Anderson, Keaven M and Zhang, Yilong},
  booktitle = {PharmaSUG},
  year      = {2020},
  url       = {https://www.pharmasug.org/proceedings/2020/DV/PharmaSUG-2020-DV-198.pdf}
}


Merck/r2rtf documentation built on April 18, 2024, 11:51 a.m.