
tflmetaR provides a simple interface for retrieving
titles, headers, and footnotes for tables, listings, and figures (TFLs)
in clinical study reports (CSRs) or other formal deliverables from a
metadata file.
Best practices in programming recommend separating code from metadata to improve readability, maintainability, and scalability. However, many R scripts used for clinical reporting still hardcode TFL annotations directly in the programs, making codebases difficult to manage and extend.
tflmetaR bridges this gap. Although independent and
self-contained, it is compatible with the {gridify}
and integrates with the Pharmaverse ecosystem for generating
submission-ready statistical deliverables.
tflmetaR supports two workflows: a concise
single-function interface and a more flexible helper-function
workflow.
You can install the newest release version from CRAN:
install.packages("tflmetaR")The metadata file can be an Excel file (.xlsx,
.xls) or a CSV file (.csv), with standardized
column names. Required columns are PGMNAME (program name),
TTL1 (primary title), FOOT1 (first footnote),
and SOURCE (data source). Additional columns for subtitles
(TTL2, TTL3, …), further footnotes
(FOOT2, FOOT3, …), population definitions,
book mark and bylines are also supported. If your file uses different
column names, use change_colname() to remap them to the
expected names before passing the file to any tflmetaR
function.
The typical workflow is to retrieve annotation metadata from a
metadata file and apply it to a TFL object created with packages such as
{gt}, {flextable},
or {ggplot2},
or with lower-level grid tools such as grob or
gtable. Metadata can be retrieved in two ways.
Option 1: Single-function interface
Use tflmetaR() to retrieve the required metadata in a
single call:
path <- system.file("extdata", "sample_titles.xlsx", package = "tflmetaR")
pgmname <- "t_dm"
title_info <- tflmetaR(
path,
by_value = pgmname,
annotation = "TITLE",
add_footr_tstamp = FALSE
)
footnotes <- tflmetaR(
path,
by_value = pgmname,
annotation = "FOOTR",
add_footr_tstamp = FALSE
)Option 2: Helper-function workflow (recommended)
Read the metadata file once with read_tfile(), then
retrieve the required metadata with the get_*() helper
functions. This avoids repeated I/O operations when annotating multiple
fields:
meta <- read_tfile(filename = path)
title_info <- get_title(meta, pname = pgmname)
footnotes <- get_footnote(meta, pname = pgmname, add_footr_tstamp = FALSE)The following example creates a table using {gt} and
annotates it with titles and footnotes retrieved from a metadata file
using {tflmetaR}.
library(tflmetaR)
library(gt)
# Locate example metadata file
path <- system.file("extdata", "sample_titles.xlsx", package = "tflmetaR")
pgmname <- "t_dm"
# Retrieve annotation metadata (Option 2: helper-function workflow)
meta <- read_tfile(filename = path)
titles <- get_title(meta, pname = pgmname)
footnotes <- get_footnote(meta, pname = pgmname, add_footr_tstamp = FALSE)
# Create the annotated gt table
tbl <- mtcars |>
head(5) |>
gt::gt() |>
gt::tab_header(
title = titles$TTL1[[1]],
subtitle = gt::html(titles$TTL2[[1]])
) |>
gt::tab_footnote(footnote = footnotes$FOOT1[[1]]) |>
gt::tab_footnote(footnote = footnotes$FOOT2[[1]]) |>
gt::tab_options(table.width = gt::pct(80))
tbl| Table 2.1 | ||||||||||
| Sample Table Using mtcars Data | ||||||||||
| mpg | cyl | disp | hp | drat | wt | qsec | vs | am | gear | carb |
|---|---|---|---|---|---|---|---|---|---|---|
| 21.0 | 6 | 160 | 110 | 3.90 | 2.620 | 16.46 | 0 | 1 | 4 | 4 |
| 21.0 | 6 | 160 | 110 | 3.90 | 2.875 | 17.02 | 0 | 1 | 4 | 4 |
| 22.8 | 4 | 108 | 93 | 3.85 | 2.320 | 18.61 | 1 | 1 | 4 | 1 |
| 21.4 | 6 | 258 | 110 | 3.08 | 3.215 | 19.44 | 1 | 0 | 3 | 1 |
| 18.7 | 8 | 360 | 175 | 3.15 | 3.440 | 17.02 | 0 | 0 | 3 | 2 |
| ES = Enrolled Set | ||||||||||
| Reference: Listing 2.1 | ||||||||||
tflmetaR() — Single-call interface for retrieving
annotation metadataread_tfile() — Read metadata from Excel or CSVget_title() — Retrieve titles and subtitlesget_footnote() — Retrieve footnotesget_source() — Retrieve data sourceget_pop() — Retrieve populationget_byline() — Retrieve bylinesget_pgmname() — Retrieve program nameget_bookm() — Retrieve bookmarkget_ulheader() — Retrieve upper-left header
contentget_urheader() — Retrieve upper-right header
contentchange_colname() — Standardize column names in the
metadata filetflmetaR is designed to work alongside:
{gridify}
— for layout and rendering annotated TFLsFor more information please visit the following vignettes:
vignette("table-example", package = "tflmetaR") - Using
tflmetaR with gt for Professional Tables.vignette("f_km", package = "tflmetaR") - Creating
Kaplan-Meier Survival Plots with tflmetaR and
gridify.Along with the authors and contributors, thanks to the following people for their support:
Alberto Montironi, Maciej Nasinski