CI/CD in the {pharmaverse}

R/Pharma

November 10th, 2022

Ben Straub (GSK) & Craig Gower-Page (Roche)

What is CI/CD?

  • Continuous Integration (CI): Frequent merging of several small changes into a main branch
  • Continuous Delivery (CD): Repeatable deployment process when deciding to deploy

CI/CD bridges the gaps between development and operation activities and teams by enforcing automation in building, testing and deployment of applications. CI/CD services compile the incremental code changes made by developers, then link and package them into software deliverables

Does it help?

…Yes! Yes, it does!!

How does CI/CD help R packages?

  • Catch issues (bugs) early on
  • User base on multiple OSes and multiple R versions
  • Faster turnaround on Code Review
  • Multiple Contributors on your R Package
  • Enforce style conventions and preferences
  • Measure test coverage for new code
  • Keep docs up-to-date
  • And we can just keep going!

We just did all these in the R/Pharma Workshop: Intro to CI/CD for R Packages

Case Study - admiral

About admiral


  • Provide an open source, modularized toolbox that enables the pharmaceutical programming community to develop ADaM datasets in R.
  • ADaM is one of the required standards for data submission to FDA (U.S.) and PMDA (Japan) for clinical trials
  • Links
  • Issue 1: Checking ADaM Template code
  • Issue 2: Common CI/CD workflows for the admiral family of packages

Issue 1 - How to Check our Template Code

  • Create a reference files to build common ADaM datasets that shows users how to implement our functions
  • Way less text than a Vignette - Code is ready to go and build a dataset
  • Where we store this code is not checked by R-CMD
  • How to ensure code stays up to date with deprecated functions or unforeseen bugs get in from functions working together?
  • CI/CD for the win!

Solution 1 - CI/CD for Templates

  • Dedicated CI/CD workflow that executes the Template code
  • Once a Code Review is completed the Check Template Workflow is executed
  • If any errors or warnings are detected the CI/CD check fails and the contributor must fix the error or warning.

.github/workflows/check-templates.yml

Issue 2 - admiral upstream and downstream dependencies

  • As you can imagine there can be a lot of different types of ADaMs!
  • Extension packages focus on specific disease areas like oncology
  • The admiral family has a package for developers, template R package repo and dummy data
  • Eek!! How to keep this all in line!

Solution 2 - Common CI/CD workflows for admiral upstream and downstream dependencies

  • Using admiralci, we have a common set of CI/CD workflows
  • Developers moving between packages are familiar with these workflows
  • Common documentation between packages for CI/CD workflows - easy to maintain and provide to new contributors

Case Study - NEST

About NEST


  • A collection of R packages for creating TLGs/TFLs and exploratory clinical trials data visualization
  • tern for creating TLGs
  • teal for creating exploratory web applications for analyzing clinical trial data
  • Links

Use Case 1 - Testing Packages as a Cohort


  • An in-development package must be tested against the latest versions of upstream dependencies
  • Monorepo emulation via a git branch naming strategy is achieved by using
  • Testing as a cohort can be done at any stage (eg. development, pre-release, release)

Use Case 2 - Shiny App Testing & Deployment


  • Analysts create Shiny web apps via the teal framework for analyzing data
  • Apps are tested via a CI pipeline that uses the shinytest2 R package
  • Apps deployed to an RSConnect Server instance via a CD pipeline

Use Case 3 - Validating R Packages


  • R packages are validated by an internal validation team that uses CI/CD pipelines to automatically
    • accept new package submissions via a form
    • running tests against the new package to ensure package integrity
    • enforcing criteria to ensure that the package meets regulatory requirements
  • Also validated externally via an open source project called thevalidatoR

Case Study - rbmi

About rbmi


Package Development Problems


  • Installation takes >3 minutes to compile STAN code
  • Full test suite takes >50 minutes to run
  • Vignettes took >5 minutes to run
  • Need to release on in-house servers running legacy versions of R
  • Many PR’s forgot to run devtools::document()
  • Many PR’s forgot to rebuild pkgdown site

Solution 1 - Reducing the Test Suite Runtime


tests/testthat/test-bigtest.R

test_that("Some long running section", {
  skip_if_not(Sys.getenv("R_TEST_FULL") == "TRUE")

  # <rest of the test code>
})


.github/workflows/on_biweekly.yaml

on:
  schedule:
    - cron: '0 4 1,15 * *'

jobs:
  rcmdcheck-main:
    env:
      R_TEST_FULL: 'TRUE' 
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Check
        uses: ./.github/actions/rcmdcheck

Solution 2 - Reducing the Vignette Runtime


.
├── DESCRIPTION
├── R/
├── tests/
└── vignettes/
    ├── quickstart.Rmd
    ├── quickstart.html
    └── quickstart.html.asis


DESCRIPTION

Suggests: R.rsp
VignetteBuilder: R.rsp


vignettes/quickstart.html.asis

%\VignetteIndexEntry{rbmi: Quickstart}
%\VignetteEngine{R.rsp::asis}

Solution 2 - Reducing the Vignette Runtime


.github/workflow/on_pr.yaml

  vignettes:
    runs-on: ubuntu-latest
    container:
      image: "ghcr.io/insightsengineering/rbmi:latest"
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Build Vignettes
        run: |
          Rscript ./vignettes/build.R

Solution 3 - Testing Against In-House Servers


Solution 3 - Testing Against In-House Servers


.github/workflows/on_pr_main.yaml

jobs:
  rcmdcheck:
    strategy:
      matrix:
       config:
        - { image: "ghcr.io/insightsengineering/rbmi:r404"}
        - { image: "ghcr.io/insightsengineering/rbmi:r410"}
        - { image: "ghcr.io/insightsengineering/rbmi:latest"}
    runs-on: ubuntu-latest
    container:
      image: ${{ matrix.config.image }}
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        
      - name: Build src
        uses: ./.github/actions/build-src
        
      - name: Check
        uses: ./.github/actions/rcmdcheck

Additional Materials