Elevating Public Health Decision Making with R Packages

Kylie Ainslie

Look familiar?

What if there was a better way?

➡️

How?

Structure your project as an R package

  • Organize
  • Document
  • Share

Let’s travel back in time

June 2021 in the Netherlands

June 2021 in the Netherlands

June 2021 in the Netherlands

Should the Netherlands extend COVID-19 vaccination to adolescents and children?

Organize

Typical Project

myproject/
├── analysis.R
├── analysis_FINAL.R
├── analysis_FINAL_v2.R
├── code_guide.pdf
├── data_raw.csv
├── final_report.pdf
├── final_report_FINAL.pdf
├── functions.R
├── methodology.docx
└── more_functions.R

Package Structure

📦 mypackage/
├── R/            # Code
├── inst/extdata/ # Data + Scripts 
├── man/          # Help files
└── vignettes/    # Analysis

Organize

Typical Project

myproject/
├── analysis.R
├── analysis_FINAL.R
├── analysis_FINAL_v2.R
├── code_guide.pdf
├── data_raw.csv
├── final_report.pdf
├── final_report_FINAL.pdf
├── functions.R
├── methodology.docx
└── more_functions.R

Package Structure

📦 mypackage/
├── R/            # Code
    ├── functions.R
    └── more_functions.R
├── inst/extdata/ # Data + Scripts 
├── man/          # Help files
└── vignettes/    # Analysis

Organize

Typical Project

myproject/
├── analysis.R
├── analysis_FINAL.R
├── analysis_FINAL_v2.R
├── code_guide.pdf
├── data_raw.csv
├── final_report.pdf
├── final_report_FINAL.pdf
├── functions.R
├── methodology.docx
└── more_functions.R

Package Structure

📦 mypackage/
├── R/            # Code
├── inst/extdata/ # Data + Scripts
    ├── analysis.R
    ├── analysis_FINAL.R
    ├── analysis_FINAL_v2.R
    └── data_raw.csv
├── man/          # Help files
└── vignettes/    # Analysis

Organize

Typical Project

myproject/
├── analysis.R
├── analysis_FINAL.R
├── analysis_FINAL_v2.R
├── code_guide.pdf
├── data_raw.csv
├── final_report.pdf
├── final_report_FINAL.pdf
├── functions.R
├── methodology.docx
└── more_functions.R

Package Structure

📦 mypackage/
├── R/            # Code
├── inst/extdata/ # Data + Scripts
├── man/          # Help files
└── vignettes/    # Analysis
    ├── code_guide.Rmd
    ├── methodology.Rmd
    └── report.Rmd

Impact: Organization → Efficiency

  • 🔄 Models rapidly updated as new data became available
  • Analysis delivered on time
  • 💉 Directly informed health policy decisions

Document

Separate Documents

myproject/
├── analysis.R
├── analysis_FINAL.R
├── analysis_FINAL_v2.R
├── code_guide.pdf
├── data_raw.csv
├── final_report.pdf
├── final_report_FINAL.pdf
├── functions.R
├── methodology.docx
└── more_functions.R

Documentation lives WITH the code

📦 mypackage/
├── R/           
├── man/         # Help files
    ├── hello_world.Rd
    ├── do_something.Rd
    └── busy_busy_busy.Rd
└── vignettes/   # Docs + Reports
    ├── code_guide.Rmd
    ├── methodology.Rmd
    └── report.Rmd

Document

#' Calculate Required Coffee for Debugging Session
#'
#' @param error_messages Integer. Number of different error messages
#' @param browser_tabs Integer. Troubleshooting browser tabs currently open
#' @param hours_stuck Numeric. Hours spent on current bug
#'
#' @return Integer. Recommended cups of coffee (max 3 for your health)
#'
#' @examples
#' coffee_for_debugging(1, 2, 0.5)
#'
#' @author Caffeinated Coder
#' 
coffee_for_debugging <- function(error_messages,browser_tabs, hours_stuck){
  
  coffee_needed <- error_messages + (browser_tabs * 0.2) + hours_stuck
  result <- min(ceiling(coffee_needed), 3)  # Cap at 3 cups
  
  if (result >= 3) {
    message("Maybe try rubber duck debugging instead?")
  }
  return(result)
}

Document

Document

Separate Documents

myproject/
├── analysis.R
├── analysis_FINAL.R
├── analysis_FINAL_v2.R
├── code_guide.pdf
├── data_raw.csv
├── final_report.pdf
├── final_report_FINAL.pdf
├── functions.R
├── methodology.docx
└── more_functions.R

Documentation lives WITH the code

📦 mypackage/
├── R/           
├── man/         # Help files
    ├── hello_world.Rd
    ├── do_something.Rd
    └── busy_busy_busy.Rd
└── vignettes/   # Docs + Reports
    ├── code_guide.Rmd
    ├── methodology.Rmd
    └── report.Rmd

Document

Document

Separate Documents

myproject/
├── analysis.R
├── analysis_FINAL.R
├── analysis_FINAL_v2.R
├── code_guide.pdf
├── data_raw.csv
├── final_report.pdf
├── final_report_FINAL.pdf
├── functions.R
├── methodology.docx
└── more_functions.R

Documentation lives WITH the code

📦 mypackage/
├── R/           
├── man/         # Help files
    ├── hello_world.Rd
    ├── do_something.Rd
    └── busy_busy_busy.Rd
└── vignettes/   # Docs + Reports
    ├── code_guide.Rmd
    ├── methodology.Rmd
    └── report.Rmd

Impact: Documentation → Transparency

  • 🛡️ Policy decisions backed by transparent analysis
  • 💡 Public could understand scientific basis for decisions
  • 🤝 More public trust

Share

Share

Share

  • ⚙️ Easy Installation
  • ➡️ Seamless Handovers
  • 🛠️ Reusable Tools
  • 🧑‍🤝‍🧑 Facilitates Collaboration

Impact: Sharing → Reproducibility

  • Incorporated into epidemics package transmission model library

  • 📉 Used to inform European-wide disease modeling

  • 🌍 One national analysis became international infrastructure

Your Turn!

  • Try an R package structure for your next project
  • Tons of tools and learning materials available
  • You’ll never go back to messy folders

Announcement

I’ve just had my first R package accepted to CRAN!

Get in touch!

linkedin.com/in/kylieainslie

@kylieainslie.bsky.social

github.com/kylieainslie

kylieainslie.github.io