Pharma
R packages
GxP
Pharma series · part 7

R in regulatory submissions and {pkglite}

What the R submission pilots showed, and packing R packages into plain text for review

What the R Consortium R submission pilots to the FDA tested, and how {pkglite} packs R packages into plain text that an eCTD submission can carry.
Published

2026-09-27

Modified

2026-09-27

The problem

Earlier in this series, we traced how clinical trial teams engineer the clinical reporting pipeline in R: raw data flows into SDTM tabulations, derives into ADaM analysis datasets, calculates into Analysis Results Data, and renders into tables, figures, and listings reconciled through independent double programming.

Eventually, this analytical pipeline must leave your local environment and enter the health authority review portal. In the United States, regulatory filings to the Food and Drug Administration (FDA) Center for Drug Evaluation and Research (CDER) are governed by Section 745A(a) of the Federal Food, Drug, and Cosmetic Act, which mandates electronic filings under the Electronic Common Technical Document (eCTD) standard.

Statistical reviewers at health authorities do not accept summary reports on faith. Under the FDA’s Study Data Technical Conformance Guide, reviewers receive the statistical programs used to generate primary efficacy and safety results so they can inspect derivations and independently replicate analysis tables.

Here clinical software engineering encounters a strict transport boundary. Within an eCTD filing, clinical study reports and analysis code reside under Module 5:

m5/datasets/<study-id>/analysis/adam/programs/

Only certain file types are accepted in these folders, and for years package archives such as .tar.gz were not among them.

A standalone, thousand-line R script is rarely how mature engineering teams organise clinical analyses. Robust reporting pipelines rely on structured R packages that bundle shared derivation algorithms, dataset validation rules, and documentation. But how can a sponsor deliver a full R package hierarchy through an electronic gateway that historically accepted only plain text files?

The web-repo way

In cloud and web engineering, shipping a reproducible build to an external environment is an established pattern:

  • Lockfiles (package-lock.json, poetry.lock, Cargo.lock) capture cryptographic content hashes and exact transitive dependency versions.
  • Software Bills of Materials (SBOMs) provide a complete manifest of every runtime library and dependency.
  • Container images (OCI / Docker) package the system libraries and runtimes an application needs (containers share the host’s kernel).
  • Artefact registries distribute versioned build artefacts as immutable packages.

The objective in clinical submissions is identical: transfer an isolated, self-contained analytical bundle to an external reviewer so they can reproduce identical results.

A regulatory reviewer’s environment is not a cloud deployment: the file types a submission may contain are restricted, and a reviewer should be able to read the code before running it. Plain text meets both needs.

What the R Consortium submission pilots tested

The R Consortium’s R Submissions Working Group has run a series of pilot submissions to the FDA, each testing one more piece of an R-based submission. Their submission packages, including the FDA’s responses, are public on GitHub (for example Pilot 1).

  • Pilot 1 (submitted November 2021, revised February 2022, final FDA response March 2022): four TLFs from simulated CDISC pilot data. The sponsor’s own helper package was delivered as a single text file, r0pkg.txt, packed with {pkglite}.
  • Pilot 2 (2022–2024): a Shiny app showing the Pilot 1 TLFs with basic filtering, bundled as a package and delivered as r1pkg.txt. The FDA’s summary letter is dated 27 September 2023.
  • Pilot 3 (2023–2024): ADaM datasets derived in R, plus the TLFs. The renv.lock file went in as renv-lock.txt, and a helper package as a .zip file (pilot3utils_0.0.2.zip).
  • Pilot 4 (2024–2025): the Shiny app again, using WebAssembly (webR) and containers; the app’s files were delivered as a {pkglite} text file (pilot4_webR_pkglite.txt).

The August 2025 file-format update

In August 2025, a revision of the FDA’s eCTD Technical Conformance Guide (Section 9.3) added file types for delivering R packages (.rds, .rdb, .rdx, .rdata/.rda, .md, .rd) and widened the use of .zip and .html, so a non-public package can now go in as a .zip file. The R Consortium’s announcement credits the pilots’ collaboration with FDA reviewers. Plain text is still useful: anyone can read and diff it before running anything.

The R way: serializing packages with {pkglite}

The {pkglite} package (Zhao et al., 2023) provides a grammar and file standard for converting R packages into plain-text files and restoring them.

The packed output follows the Debian Control File (DCF) standard—the same key-value syntax used in Debian package management, R DESCRIPTION files, and read.dcf(). Each file in the package is serialised into a distinct block separated by a blank line:

Package: submissionpkg
File: R/derive_study_day.R
Format: text
Content:
  #' Derive study day from reference date (no day 0 in clinical trials)
  #' @param trt_dt Treatment date
  #' @param ref_dt Reference date (e.g. TRTSDTM)
  #' @return Integer study day
  #' @export
  derive_study_day <- function(trt_dt, ref_dt) {
    diff_days <- as.integer(trt_dt - ref_dt)
    ifelse(diff_days >= 0L, diff_days + 1L, diff_days)
  }

Text files are indented by two spaces and stored verbatim. Binary files (such as .rda datasets) are stored as hexadecimal, following the RTF format convention (the package’s format vignette), so the whole file stays ASCII; verify_ascii() checks it.

Packing a package

The {pkglite} workflow uses three core verbs: collate(), pack(), and unpack().

First, let us construct a minimal submission utility package in a temporary directory:

library(pkglite)

pkg_dir <- file.path(tempdir(), "submissionpkg")
dir.create(pkg_dir, showWarnings = FALSE)
dir.create(file.path(pkg_dir, "R"), showWarnings = FALSE)

writeLines(
  c(
    "Package: submissionpkg",
    "Title: Submission Utility Package",
    "Version: 0.1.0",
    "Description: Helper utilities for clinical trial analysis.",
    "License: Apache License (>= 2)",
    "Encoding: UTF-8"
  ),
  file.path(pkg_dir, "DESCRIPTION")
)

writeLines("export(derive_study_day)", file.path(pkg_dir, "NAMESPACE"))

writeLines(
  c(
    "#' Derive study day from reference date (no day 0 in clinical trials)",
    "#' @param trt_dt Treatment date",
    "#' @param ref_dt Reference date (e.g. TRTSDTM)",
    "#' @return Integer study day",
    "#' @export",
    "derive_study_day <- function(trt_dt, ref_dt) {",
    "  diff_days <- as.integer(trt_dt - ref_dt)",
    "  ifelse(diff_days >= 0L, diff_days + 1L, diff_days)",
    "}"
  ),
  file.path(pkg_dir, "R", "derive_study_day.R")
)

We evaluate the file scope with pkglite::file_ectd() and pack the collection into a text file:

# Collate the files that the eCTD file specification selects
fc <- pkglite::collate(pkg_dir, pkglite::file_ectd())
fc$df[, c("path_rel", "format")]

# Pack into a single plain text file
txt_file <- file.path(tempdir(), "submissionpkg.txt")
pkglite::pack(fc, output = txt_file, quiet = TRUE)

# Verify ASCII compliance for eCTD gateway submission
is_clean_ascii <- pkglite::verify_ascii(txt_file, quiet = TRUE)
is_clean_ascii
# Inspect the top of the generated DCF file
head(readLines(txt_file), n = 12L)

pkglite::file_ectd() is the file specification {pkglite} provides for eCTD submissions (its help: “a combination of file specifications for eCTD submissions”); it selects a narrower set of files than pkglite::file_default().

Unpacking on the reviewer side

On the reviewer’s workstation, restoring the complete package directory tree requires a single call:

restored_root <- file.path(tempdir(), "review_workspace")
pkglite::unpack(input = txt_file, output = restored_root, quiet = TRUE)

# Verify the restored directory structure
list.files(file.path(restored_root, "submissionpkg"), recursive = TRUE)

To install the packages after unpacking them, unpack() takes install = TRUE (as the package’s vignette shows):

# Unpack and install the package into the reviewer's active library
pkglite::unpack(
  input = "submissionpkg.txt",
  output = "review_workspace",
  install = TRUE
)

Reproducibility is a three-tier discipline

Packaging code into plain text solves file transfer across regulated gateways, but transport is only the first tier of clinical reproducibility:

┌────────────────────────────────────────────────────────┐
│ Tier 3: Execution Runtime                              │
│ Pinned R version, OS libraries and compilers           │
├────────────────────────────────────────────────────────┤
│ Tier 2: Dependency Lockfile                            │
│ renv.lock (sent as renv-lock.txt in Pilot 3)           │
├────────────────────────────────────────────────────────┤
│ Tier 1: Source Packaging                               │
│ Proprietary functions & data bundled via pkglite (.txt)│
└────────────────────────────────────────────────────────┘
  1. Source package tier: {pkglite} serialises and restores the exact directory structure, code files, and internal data objects.
  2. Dependency tier: An renv.lock file records the exact versions and sources of the open-source packages (such as {admiral}, {rtables}, and {cards}). In submissions, this is submitted alongside the code as renv-lock.txt and restored with renv::restore().
  3. Execution runtime tier: The R version and relevant system details, documented for the reviewer (for example in the Analysis Data Reviewer’s Guide, as the pilots did).

If any of these three tiers is missing, code that runs cleanly on a sponsor’s laptop will fail when an external reviewer attempts replication.

Honest GxP framing

No tool is “regulatory approved”: the FDA reviews a sponsor’s submission and its evidence, not programming languages or packages.

Using {pkglite} does not make a clinical submission valid by itself. What it provides is a transparent, inspectable packaging protocol that respects health authority gateway file specifications. What makes code reviewable is the combination: readable packaging, a pinned environment, clear reviewer documentation and tests.

Companion code

View pkglite-demo.R · Download

Builds a throwaway package in a temporary directory, serialises it with {pkglite} into a .txt file, restores it to a new location, and verifies every file byte for byte. Requires {pkglite}.

# Builds a tiny throwaway package, packs it with pkglite into a plain-text
# file (.txt), restores it to an unpacked directory, and verifies file
# trees and byte-level contents.
#
#   Rscript pkglite-demo.R

create_demo_package <- function(pkg_dir) {
  if (!dir.exists(pkg_dir)) {
    dir.create(pkg_dir, recursive = TRUE)
  }
  dir.create(file.path(pkg_dir, "R"), showWarnings = FALSE)
  dir.create(file.path(pkg_dir, "data"), showWarnings = FALSE)

  desc_content <- c(
    "Package: tinypkg",
    "Title: Minimal Demo Package for pkglite",
    "Version: 0.1.0",
    "Description: Minimal package for packing and unpacking with pkglite.",
    "License: Apache License (>= 2)",
    "Encoding: UTF-8"
  )
  writeLines(desc_content, file.path(pkg_dir, "DESCRIPTION"))

  writeLines("export(add_one)", file.path(pkg_dir, "NAMESPACE"))

  r_content <- c(
    "#' Add one to a numeric value",
    "#' @param x Numeric input",
    "#' @return x + 1L",
    "#' @export",
    "add_one <- function(x) {",
    "  x + 1L",
    "}"
  )
  writeLines(r_content, file.path(pkg_dir, "R", "add_one.R"))

  toy <- data.frame(
    subjid = c("01", "02"),
    val = c(10L, 20L),
    stringsAsFactors = FALSE
  )
  save(toy, file = file.path(pkg_dir, "data", "toy.rda"))

  invisible(pkg_dir)
}

pack_demo_package <- function(
  pkg_dir,
  txt_path = file.path(tempdir(), "tinypkg.txt"),
  spec = pkglite::file_default()
) {
  fc <- pkglite::collate(pkg_dir, spec)
  pkglite::pack(fc, output = txt_path, quiet = TRUE)
  list(txt_path = txt_path, file_collection = fc)
}

unpack_demo_package <- function(txt_path, out_dir) {
  if (!dir.exists(out_dir)) {
    dir.create(out_dir, recursive = TRUE)
  }
  pkglite::unpack(input = txt_path, output = out_dir, quiet = TRUE)
  file.path(out_dir, "tinypkg")
}

compare_packages <- function(orig_dir, restored_dir, rel_paths) {
  results <- lapply(rel_paths, function(rel_path) {
    orig_file <- file.path(orig_dir, rel_path)
    restored_file <- file.path(restored_dir, rel_path)

    exists_orig <- file.exists(orig_file)
    exists_restored <- file.exists(restored_file)

    if (!exists_orig || !exists_restored) {
      return(data.frame(
        file = rel_path,
        exists_orig = exists_orig,
        exists_restored = exists_restored,
        byte_identical = FALSE,
        stringsAsFactors = FALSE
      ))
    }

    orig_bytes <- readBin(orig_file, "raw", n = file.info(orig_file)$size)
    restored_bytes <- readBin(
      restored_file,
      "raw",
      n = file.info(restored_file)$size
    )

    data.frame(
      file = rel_path,
      exists_orig = exists_orig,
      exists_restored = exists_restored,
      byte_identical = identical(orig_bytes, restored_bytes),
      stringsAsFactors = FALSE
    )
  })

  do.call(rbind, results)
}

if (sys.nframe() == 0L) {
  demo_root <- file.path(tempdir(), "pkglite-demo-run")
  pkg_dir <- file.path(demo_root, "tinypkg")
  unpack_dir <- file.path(demo_root, "restored")
  txt_path <- file.path(demo_root, "tinypkg.txt")

  message("Creating throwaway package...")
  create_demo_package(pkg_dir)

  message("Packing package into plain text with pkglite...")
  pack_res <- pack_demo_package(pkg_dir, txt_path = txt_path)

  is_ascii <- pkglite::verify_ascii(txt_path, quiet = TRUE)
  message("ASCII verification: ", if (is_ascii) "PASS" else "FAIL")

  message("Restoring package to new directory...")
  restored_pkg <- unpack_demo_package(txt_path, unpack_dir)

  rel_paths <- pack_res$file_collection$df$path_rel
  comparison <- compare_packages(pkg_dir, restored_pkg, rel_paths)

  print(comparison)
  all_match <- all(comparison$byte_identical)
  message(
    "Round trip status: ",
    if (all_match) "ALL FILES MATCH EXACTLY" else "DISCREPANCIES FOUND"
  )
}

Sources

Package documentation

Standards and organisations

Further reading

References worth reading alongside this post (official documents, linked for context rather than quoted line by line):

  • FDA, Electronic Common Technical Document (eCTD), including the requirement for electronic submissions: fda.gov
  • FDA, Study Data Technical Conformance Guide: fda.gov
  • FDA, eCTD Technical Conformance Guide (PDF; Section 9.3 covers file formats): fda.gov
NoteUpdates
  • 2026-09-27: Added a Companion code section with the full script.