renv::init() # once per project
renv::snapshot() # after approving the package set
renv::restore() # on any new machine: identical environmentHow to Write an R Validation Plan for Regulatory Submissions
- Regulators do not validate software; you validate your use of it. An R validation plan documents the intended use, the risks, the controls and the evidence.
- The plan has eight parts: scope, roles, risk assessment, environment qualification (IQ/OQ), package qualification, process controls (dual programming, code review), traceability, and deviation management ending in a validation summary report.
- Pin the environment with renv, qualify it by running package test suites, assess packages with riskmetric against written acceptance criteria, and record
sessionInfo()in every production run. - Keep the plan short enough to be read and the evidence large enough to be audited. Most plans are 15-25 pages; the evidence pack is whatever your pipeline produces automatically.
“Is R validated?” is the first question a sponsor’s QA group asks and the one most often answered badly. The honest answer is that no statistical software is validated in the abstract. The FDA’s position, repeated in its Statistical Software Clarifying Statement and demonstrated by the R Consortium submission pilots, is that sponsors must be able to show their analyses are reproducible, documented and controlled. A validation plan is where you show it. This is the structure we use.
1. Scope and intended use
State what R will be used for and what it will not. Typical scope: ADaM dataset derivation, TLF production and statistical analysis for named studies or for a programme. Out of scope might be data management or SDTM mapping if those remain elsewhere. Naming the intended use makes the risk assessment concrete.
2. Roles and responsibilities
Who owns the environment, who approves packages, who performs independent QC, who signs the summary. In a migration this section also names the SAS reference programmer for the parallel-run phase.
3. Risk assessment
A short table, usually one page: for each use (dataset derivation, descriptive tables, inferential analysis, figures), the impact of an error (patient safety, regulatory decision, operational), the likelihood given controls, and the resulting control level. High-impact uses get full dual programming; low-impact ones may get code review plus spot checks. Writing this down is what allows you to not dual-program a listing and still be compliant.
4. Environment qualification
Installation qualification (IQ). Record R version, operating system, compiler, BLAS/LAPACK, and the exact package set. renv produces the lockfile; store it with the study.
Operational qualification (OQ). Prove the installation behaves as the package authors intend by running their test suites in your environment and filing the results:
tools::testInstalledPackage("survival", types = "tests")
tools::testInstalledPackage("admiral", types = "tests")Base R itself ships regression tests (make check-all at build time, or tools::testInstalledBasic("both")). Attach the logs to the IQ/OQ record. Re-qualify whenever the lockfile changes.
Session evidence. Every production run writes sessionInfo() (or sessioninfo::session_info()) and the lockfile hash to the log. This is what lets an auditor tie an output to an environment three years later.
5. Package qualification
Packages are the part reviewers worry about. The plan defines acceptance criteria and a procedure:
- Criteria might be: on CRAN or Bioconductor or an approved internal repository; documented exports; a test suite with meaningful coverage; active maintenance (release or commit within 24 months); a licence compatible with use.
- Assessment uses
riskmetricto compute standard metrics (documentation, tests, maintenance, community usage) and store the scores:
library(riskmetric)
pkg_ref(c("admiral", "rtables", "gtsummary", "survival")) |>
pkg_assess() |>
pkg_score()- Decision record. For each package: scores, the criteria met, the approver and the date. Low-scoring packages can still be approved with additional controls (for example, dual programming of every output that depends on them), but the decision is written.
The pharmaverse packages (admiral, rtables, tern, xportr, metacore) publish extensive tests and are used by multiple sponsors, which is exactly the evidence the criteria ask for.
6. Process controls
Programming standards. A short document: file layout, naming, how specifications are referenced in code, how derivations are commented, when functions must be packaged. See turning SAS macros into R functions.
Independent QC. Dual programming for everything the risk assessment marks as high impact, with the numerical tolerance rules referenced here. Code review for everything else.
Version control. Git, with the production branch protected and each delivery tagged. The tag, the lockfile hash and the output checksums go in the delivery note.
7. Traceability
A traceability matrix links every requirement to its implementation and evidence: SAP section → specification item → program/function → output → QC record. In practice this is a table you can generate from metadata rather than maintain by hand. Read building a traceability matrix for statistical programming.
8. Deviations and the summary report
Define what counts as a deviation (a failed comparison outside tolerance, a package used outside approval, a run on an unqualified environment), how it is logged, who resolves it, and how resolution is verified. The validation summary report closes the plan: what was planned, what was executed, counts of comparisons and deviations, open items, and a signed statement that the system is fit for its intended use.
How long does this take?
For a team migrating a first study, the plan itself is one to two weeks of writing with QA review. Environment and package qualification is largely automated once set up and takes days. The ongoing cost is the dual programming you would be doing anyway. The output is a document set your QA group can file and a sponsor can audit. If you are starting from scratch, our SAS to R migration service delivers the plan, the templates and the first evidence pack as Phase 4 of the five-phase roadmap.
Background reading: Is R accepted by the FDA? and qualifying R packages with riskmetric.