R Programming and Pharmaceutical Data Analysis (Packages for Clinical Trial Data)

Reading time:
time
min

In the clinical trials reporting industry, there is an incorrect assumption that <a href="https://appsilon.com/sas-vs-r-programming/#SAS" target="_blank" rel="noopener">SAS software</a> is ideal as regulatory agencies "require" it. Regulatory agencies generally do not mandate the use of specific software for clinical trial reporting. They primarily focus on the accuracy, integrity, and compliance of the reported data. Recently, other software options, such as the open-source R language, have gained attention across the life sciences, despite facing resistance due to this misconception. R has a strong history of use in academia for statistical research and is being <a href="https://appsilon.com/r-shiny-pharma-biotech-examples/" target="_blank" rel="noopener">utilized in the pharmaceutical industry</a>. However, its adoption in regulatory submissions has been limited. In recent years, developers from the pharmaceutical industry have taken advantage of R and collaboratively developed open-source libraries that can be used in clinical trials data analysis and reporting. This blog article/post will provide an overview of a few R packages, including their key features and how they can be used, along with resources for learning more about them. <h3>Open Source and Proprietary Works</h3> Please note, this is not legal advice! Explore Posit's responses to related questions on: <ul class="p-rich_text_list p-rich_text_list__bullet" data-stringify-type="unordered-list" data-indent="0" data-border="0"><li data-stringify-indent="0" data-stringify-border="0"><a class="c-link" href="https://community.rstudio.com/t/commercial-use-of-shiny-and-r/10287" target="_blank" rel="noopener noreferrer" data-stringify-link="https://community.rstudio.com/t/commercial-use-of-shiny-and-r/10287" data-sk="tooltip_parent">Commercial use of R and Shiny</a></li><li data-stringify-indent="0" data-stringify-border="0"><a class="c-link" href="https://community.rstudio.com/t/agpl-seems-to-prevent-use-of-shiny-applications-in-a-proprietary-environment/17795" target="_blank" rel="noopener noreferrer" data-stringify-link="https://community.rstudio.com/t/agpl-seems-to-prevent-use-of-shiny-applications-in-a-proprietary-environment/17795" data-sk="tooltip_parent">AGPL, GPL, and the use of Shiny applications in proprietary environments</a></li></ul> One of the common misconceptions about using open-source packages in software development is that it requires companies to publicly disclose their own code and proprietary workflows. This misconception often arises from the fact that many popular open-source packages, such as R and its various libraries, are licensed under the GNU General Public License (GPL) or other similar licenses that require the distribution of source code.  However, it is important to note that using open-source packages does not necessarily require companies to disclose their own code or proprietary workflows. The GPL and other similar licenses only require the distribution of source code if the software that uses the open-source packages is also distributed.  For example, if a company is developing an internal application that uses R and various open-source libraries, and that application is only used within the company, then there is no requirement to distribute the source code for that application. The company can keep its code and workflows confidential, even if it uses open-source packages. On the other hand, if a company develops a commercial application that incorporates open-source packages and then distributes that application to customers, then it may be required to distribute the source code for the application, including any modifications made to the open-source packages. However, this requirement can often be satisfied by providing access to the source code through a written offer, rather than including it with the distributed software. There is an alternative interpretation where your code, which utilizes external R libraries, is not compiled and loads the libraries into memory when the app is executed. Therefore, the library mentioned does not refer specifically to a given library from CRAN; it can be any library from your local drive with a different license. As a result, your code allows for the integration of any library that adheres to the given interface and does not rely on any specific GPL library. This indicates that your app is a separate component that uses other packages but is not linked as one product, <strong>eliminating the requirement to open-source your code</strong>. <h2>Understanding Clinical Data Standards</h2> <a href="https://www.cdisc.org/" target="_blank" rel="noopener">CDISC (Clinical Data Interchange Standards Consortium)</a> is a global, non-profit organization that develops and promotes data standards to support the acquisition, exchange, submission, and archive of clinical research data and metadata.  CDISC Foundational Standards provide a comprehensive set of data standards that improve the quality, efficiency, and cost-effectiveness of clinical research. These standards cover various aspects of clinical research, from study design to data collection, management, analysis, and reporting. The standards include the <ul><li style="font-weight: 400;" aria-level="1"><a href="https://www.cdisc.org/standards/foundational/protocol" target="_blank" rel="noopener">Protocol Representation Model (PRM)</a> </li><li style="font-weight: 400;" aria-level="1"><a href="https://www.cdisc.org/standards/foundational/send" target="_blank" rel="noopener">Standard for Exchange of Nonclinical Data (SEND)</a></li><li style="font-weight: 400;" aria-level="1"><a href="https://www.cdisc.org/standards/foundational/cdash" target="_blank" rel="noopener">Clinical Data Acquisition Standards Harmonization (CDASH)</a></li><li style="font-weight: 400;" aria-level="1"><a href="https://www.cdisc.org/standards/foundational/sdtm" target="_blank" rel="noopener">Study Data Tabulation Model (SDTM)</a></li><li style="font-weight: 400;" aria-level="1"><a href="https://www.cdisc.org/standards/foundational/sdtmig" target="_blank" rel="noopener">Study Data Tabulation Model Implementation Guide (SDTMIG)</a></li><li style="font-weight: 400;" aria-level="1"><a href="https://www.cdisc.org/standards/foundational/adam" target="_blank" rel="noopener">Analysis Data Model (ADaM)</a>.</li></ul> These standards help ensure that clinical trial data is organized and analyzed consistently and accurately, enhancing the efficiency and quality of clinical research. The <a href="https://www.cdisc.org/standards/foundational/qrs" target="_blank" rel="noopener">QRS</a> supplements provide a standardized way to assess clinical concepts or task-based observations. ADaM is required by both the <a href="https://www.fda.gov/" target="_blank" rel="noopener">FDA</a> (US) and <a href="https://www.pmda.go.jp/english/" target="_blank" rel="noopener">PMDA</a> (Japan) for new drug applications, while the FDA requires SEND for nonclinical studies. CDISC standards improve transparency and traceability, making it easier for regulators and others to conduct data reviews.  <h2>Insights Engineering</h2> <img class="aligncenter size-full wp-image-19302" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01b20fdb8ad62e9caf5c6_Insights-Engineering.webp" alt="Pharmaceutical Engineering open source R projects" width="400" height="225" /> <h4><a href="https://insightsengineering.github.io/teal/latest-tag/" target="_blank" rel="noopener"><b>{teal}: Interactive Exploratory Data Analysis with Shiny Web Applications</b></a></h4> <h4>{teal} is a framework for interactive exploratory data analysis that uses Shiny web applications. {teal} applications require specifying data, including CDISC data, independent datasets, related datasets, and MultiAssayExperiment objects. </h4> The framework also provides modules for performing analysis, such as outlier exploration and data visualization. {teal} modules are built within the framework and can be found in packages like {teal.modules.general}, {teal.modules.clinical} and {teal.modules.{hermes} }.  The framework's functionality is derived from packages like {teal.data}, {teal.widgets}, {teal.slice}, {teal.code}, {teal.transform}, {teal.logger} and {teal.reporter}. There is also a package called {teal.osprey} that takes community teal modules. Users can refer to these packages for more information on how to use different parts of the {teal} framework. <a href="https://insightsengineering.github.io/hermes/main/" target="_blank" rel="noopener"><b>{hermes}</b></a> {hermes} is a tool that helps with the preprocessing, analysis, and reporting of RNA-seq data. It has the ability to import RNAseq count data and annotate gene information from a central database like BioMart. It also adds quality control flags to genes and samples, filters the data set, and normalizes counts.  {hermes} can work with data structures from bioconductor packages, thereby allowing interoperability. It can also quickly generate descriptive plots, perform principal components analysis, and produce a QC report based on a template. Additionally, it can perform differential expression analysis. <h4><a href="https://insightsengineering.github.io/tern/latest-tag/" target="_blank" rel="noopener"><b>{tern}</b></a></h4> <h4>The R package called {tern} offers various analysis functions for generating tables and graphs commonly used in clinical trial reporting. This package provides a wide range of functionalities including data visualizations such as forest plots, line plots, Kaplan-Meier plots, as well as statistical model fits like logistic regression and Cox regression. </h4> Additionally, {tern} allows for the creation of summary tables containing information about unique patients, exposure across patients, and changes from baseline for parameters. Furthermore, {tern} outputs can be added to {teal} applications for interactive exploration of data through modules available in the {teal.modules.clinical} package. <h4><a href="https://insightsengineering.github.io/rbmi/" target="_blank" rel="noopener"><b>Reference Based Multiple Imputation {rbmi}</b></a></h4> <h4>The R package called {rbmi} is designed for imputing missing data in clinical trials with continuous multivariate normal longitudinal outcomes. It can handle missing data under a missing at random (MAR) assumption, reference-based imputation methods, and delta adjustments for sensitivity analysis like tipping point analyses. </h4> <h4>The package offers both Bayesian and approximate Bayesian multiple imputation, which is combined with Rubin's rules for inference, as well as frequentist conditional mean imputation with jackknife or bootstrap resampling.</h4> <h2>Pharmaverse</h2> <img class="aligncenter size-full wp-image-19304" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01b224c2c8ea263ddeadc_Pharmaverse.webp" alt="Pharmaverse R packages for Clinical Trial Data Analysis" width="400" height="225" /> &nbsp; <a href="https://pharmaverse.org/" target="_blank" rel="noopener">Pharmaverse</a> is a network of pharmaceutical industry professionals working collaboratively to create a curated and opinionated subset of open-source software packages and codebases based on the R language.  The objective is to deliver a complete clinical data pipeline from data collection to regulatory submission that is more efficient and sustainable through shared development and maintenance efforts, with a focus on reducing duplication of efforts and gaining increased harmonization across the industry. The initiative aims to attract the next generation of software developers and data scientists to the industry and provide increased transparency.  The scope of Pharmaverse is the journey from Case Report Form (CRF) through to submission for clinical trial analysis reporting via R packages, with three categories of R packages recommended:  <ul><li style="font-weight: 400;" aria-level="1"><b>External to pharma</b> (transcends specifically pharma needs).</li><li style="font-weight: 400;" aria-level="1"><b>Pharma-specific independent of pharmaverse</b> (created for use in pharma, but not necessarily following the pharmaverse charter and recommendations).</li><li style="font-weight: 400;" aria-level="1"><b>Pharma-specific under pharmaverse </b>(created for use in pharma, following the pharmaverse charter and recommendations). </li></ul> The aim is not to agree on cross-industry implementations of CDISC standards, but rather to act as a starting point for code reuse that is standard agnostic and future-proof. The design and architecture of the package allow companies to use them to adapt to internal workflows that are proprietary. For example, {admiral} package has {admiral.vaccines} and {admiral.ophta}, but there is also an {admiral.roche} that is internal to Roche and not shared (with proprietary license). Pharmaverse packages will be easily locatable and accessible via a single site, with clear use cases for clinical trial reporting and sharing of differences and unique merits to help companies or users choose which packages or tools to adopt. <h3><b>Pharmaverse End-to-End Clinical Reporting Packages</b></h3> Let us explore some of the End-to-End Clinical Reporting Packages from Pharmaverse. The following compilation comprises 'some' of the open-source R packages that are relevant to end-to-end clinical reporting in the pharmaceutical industry. The Pharmaverse council aims to organize and curate these packages into a well-defined stack in due course. <table> <tbody> <tr> <td><b>Package Name</b></td> <td><b>Category</b></td> <td><b>Status</b></td> <td><b>Description</b></td> <td><b>URL</b></td> </tr> <tr> <td>sdtmchecks</td> <td>SDTM</td> <td>Released</td> <td>This package contains functions to identify common data issues in SDTM data. These checks are intended to be generalizable, actionable, and meaningful for analysis.</td> <td><a href="https://pharmaverse.github.io/sdtmchecks/index.html">https://pharmaverse.github.io/sdtmchecks/index.html</a></td> </tr> <tr> <td>datacutr</td> <td>SDTM</td> <td>Upcoming</td> <td>This package processes tabulation data in compliance with the SDTM standard. It assumes that supplemental qualifiers have already been merged with their parent domain before applying the cut process. Users can choose the type of cut they want to apply to each domain, such as either no cut, patient cut, date cut, or a special DM cut.</td> <td><a href="https://pharmaverse.github.io/datacutr/main/">https://pharmaverse.github.io/datacutr/main/</a></td> </tr> <tr> <td>roak</td> <td>SDTM</td> <td>Upcoming</td> <td>Enables SDTM mapping algorithms via R functions.</td> <td>Not yet available</td> </tr> <tr> <td>admiral</td> <td>ADaM</td> <td>Released</td> <td>ADaM In R Asset Library, is an open-source and modular toolbox that empowers pharmaceutical programmers to generate ADaM datasets using R programming.</td> <td><a href="https://pharmaverse.github.io/admiral/cran-release/">https://pharmaverse.github.io/admiral/cran-release/</a></td> </tr> <tr> <td>admiralonco</td> <td>ADaM</td> <td>Released</td> <td>Complementary toolbox to admiral for enabling users to generate ADaM datasets based on oncology.</td> <td><a href="https://pharmaverse.github.io/admiralonco/main/">https://pharmaverse.github.io/admiralonco/main/</a></td> </tr> <tr> <td>admiraloptha</td> <td>ADaM</td> <td>Released</td> <td>Complementary toolbox to admiral for enabling users to generate ADaM datasets based on opthalmology.</td> <td><a href="https://pharmaverse.github.io/admiralophtha">https://pharmaverse.github.io/admiralophtha</a></td> </tr> <tr> <td>admiralvaccine</td> <td>ADaM</td> <td>Upcoming</td> <td>Complementary toolbox to admiral for enabling users to generate ADaM datasets based on vaccine domains.</td> <td><a href="https://pharmaverse.github.io/admiralvaccine/main/">https://pharmaverse.github.io/admiralvaccine/main/</a></td> </tr> <tr> <td>rtables</td> <td>TLGs - Tables</td> <td>Released</td> <td>A framework for declaring complex multi-level tabulations and then applying them to data</td> <td><a href="https://insightsengineering.github.io/rtables/">https://insightsengineering.github.io/rtables/</a></td> </tr> <tr> <td>pharmaRTF</td> <td>TLGs - Tables</td> <td>Released</td> <td>Enhanced RTF wrapper is written in R for use with existing R tables packages such as huxtable or GT</td> <td><a href="https://atorus-research.github.io/pharmaRTF/">https://atorus-research.github.io/pharmaRTF/</a></td> </tr> <tr> <td>Tplyr</td> <td>TLGs - Tables</td> <td>Released</td> <td>A package to simplify the data manipulation necessary to create clinical reports</td> <td><a href="https://cran.r-project.org/web/packages/Tplyr/index.html">https://cran.r-project.org/web/packages/Tplyr/index.html</a></td> </tr> <tr> <td>tfrmt</td> <td>TLGs - Tables</td> <td>Released</td> <td>A language for defining display-related metadata to automate the transformation from an Analysis Results Dataset (ARD) to a table</td> <td><a href="https://gsk-biostatistics.github.io/tfrmt/">https://gsk-biostatistics.github.io/tfrmt/</a></td> </tr> <tr> <td>tidytlg</td> <td>TLGs - Tables</td> <td>Released</td> <td>Generate tables, listings, and graphs (TLG) using the Tidyverse</td> <td><a href="https://pharmaverse.github.io/tidytlg">https://pharmaverse.github.io/tidytlg</a></td> </tr> <tr> <td>visR</td> <td>TLGs - Plots</td> <td>Released</td> <td>A package to enable fit-for-purpose, reusable clinical and medical research-focused visualizations and tables with sensible defaults and based on sound graphical principles</td> <td><a href="https://openpharma.github.io/visR/">https://openpharma.github.io/visR/</a></td> </tr> <tr> <td>ggplot2</td> <td>TLGs - Plots</td> <td>Released</td> <td>An implementation of the Grammar of Graphics in R, and the most popular plotting package for static plots in R</td> <td><a href="https://ggplot2.tidyverse.org/">https://ggplot2.tidyverse.org/</a></td> </tr> <tr> <td>tidyCDISC</td> <td>TLGs - Interactive</td> <td>Released</td> <td>A Shiny app to easily create custom tables and figures from ADaM-ish data sets</td> <td><a href="https://biogen-inc.github.io/tidyCDISC/">https://biogen-inc.github.io/tidyCDISC/</a></td> </tr> <tr> <td>tern</td> <td>TLGs - Frameworks</td> <td>Released</td> <td>Layers analytics from descriptive summaries to more complex statistics on top of the foundational table layouts, analytic and content controls</td> <td><a href="https://insightsengineering.github.io/tern/">https://insightsengineering.github.io/tern/</a></td> </tr> <tr> <td>teal</td> <td>TLGs - Frameworks</td> <td>Released</td> <td>A framework that leverages the R Shiny package to scale the development of shiny apps</td> <td><a href="https://insightsengineering.github.io/teal/">https://insightsengineering.github.io/teal/</a></td> </tr> <tr> <td>chevron</td> <td>TLGs - Tables</td> <td>Upcoming</td> <td>Holds TLG template standards to feed into other tabulation packages</td> <td>Not yet available</td> </tr> <tr> <td>xportr</td> <td>eSub</td> <td>Released</td> <td>Serves the dual purpose of creating SAS transport files and conducting validation checks on pharmaceutical-specific datasets.</td> <td><a href="https://atorus-research.github.io/xportr/">https://atorus-research.github.io/xportr/</a></td> </tr> <tr> <td>pkglite</td> <td>eSub</td> <td>Released</td> <td>The purpose of this is to enable the representation and exchange of R package source code in the form of text files that can be easily read and understood.</td> <td><a href="https://merck.github.io/pkglite/">https://merck.github.io/pkglite/</a></td> </tr> <tr> <td>metacore</td> <td>Metadata</td> <td>Released</td> <td>Offers an interface that allows for the ingestion of diverse metadata sources and the storage of such metadata in a uniform object.</td> <td><a href="https://atorus-research.github.io/metacore/">https://atorus-research.github.io/metacore/</a></td> </tr> <tr> <td>metatools</td> <td>Metadata</td> <td>Released</td> <td>By leveraging metadata, this tool facilitates the creation, improvement, and validation of datasets using metacore objects. This includes the ability to add or remove supplementary qualifiers from or to the parent SDTM domain.</td> <td><a href="https://pharmaverse.github.io/metatools/">https://pharmaverse.github.io/metatools/</a></td> </tr> <tr> <td>logrx</td> <td>Utility</td> <td>Released</td> <td>This tool produces an execution log which helps ensure the reproducibility and traceability of an R script.</td> <td><a href="https://pharmaverse.github.io/logrx/">https://pharmaverse.github.io/logrx/</a></td> </tr> <tr> <td>synthetic.cdisc.data</td> <td>Utility</td> <td>Released</td> <td>Generates synthetic CDISC data</td> <td><a href="https://github.com/Roche/synthetic.cdisc.data">https://github.com/Roche/synthetic.cdisc.data</a></td> </tr> <tr> <td>envsetup</td> <td>Utility</td> <td>Released</td> <td>Supports the setup of an R environment</td> <td><a href="https://pharmaverse.github.io/envsetup/main/index.html">https://pharmaverse.github.io/envsetup/main/index.html</a></td> </tr> <tr> <td>covtracer</td> <td>Package Validation</td> <td>Released</td> <td>This package offers automated tracing of code coverage by means of a network of test executions, linking tests to code and code to documentation. Its primary use case is to provide a traceability matrix for CICD-based validation.</td> <td><a href="https://github.com/Genentech/covtracer">https://github.com/Genentech/covtracer</a></td> </tr> <tr> <td>thevalidatoR</td> <td>Package Validation</td> <td>Released</td> <td>This is a GitHub action available on the GitHub Marketplace, designed to deliver consistent build reports for validation purposes. It serves as an alternative to valtools and is based on the standard R framework for validation.</td> <td><a href="https://github.com/marketplace/actions/r-package-validation-report">https://github.com/marketplace/actions/r-package-validation-report</a></td> </tr> <tr> <td>valtools</td> <td>Package Validation</td> <td>Released</td> <td>This validation framework for R packages provides the ability to incorporate supplementary validation documentation as needed.</td> <td><a href="https://phuse-org.github.io/valtools/">https://phuse-org.github.io/valtools/</a></td> </tr> <tr> <td>difffdf</td> <td>Quality Checking</td> <td>Released</td> <td>The diffdf package is intended to facilitate a comprehensive comparison of two data.frames, providing detailed insights into any differences between them.</td> <td><a href="https://gowerc.github.io/diffdf/">https://gowerc.github.io/diffdf/</a></td> </tr> </tbody> </table> <h2><b>Conclusion: R Packages for Clinical Trial Data</b></h2> The life sciences industry is expanding rapidly, and open-source initiatives have provided a significant impetus to innovation. With the advent of package developments with programming languages like R, conducting clinical trials, monitoring, and analyzing data has become more streamlined and precise.  Collaborative projects in the life sciences domain, spearheaded by pharmaceutical companies and experts, have propelled advancements in research, enabling more rapid and precise discoveries. These open-source projects, which leverage cutting-edge technologies and techniques, are expected to pave the way for accelerated progress in the life sciences industry, leading to better healthcare outcomes for people worldwide.

Have questions or insights?

Engage with experts, share ideas and take your data journey to the next level!
Explore Possibilities

Share Your Data Goals with Us

From advanced analytics to platform development and pharma consulting, we craft solutions tailored to your needs.

Talk to our Experts
r
pharma
shiny
life sciences
gxp