How mrcieu/twosamplemr works
Project type and purpose
• This is an R package (“TwoSampleMR”) for performing Mendelian randomization analyses on GWAS summary data.
• It exposes a set of R functions to the end-user and connects to the IEU OpenGWAS database to fetch input data.
• It also includes vignettes, example datasets, automated tests, and CI/CD workflows for package checking, documentation building, and coverage reporting.
a. Core R Library (R/ directory)
– All exported functions (mr(), harmonise(), clump_data(), forest_plot(), etc.)
– Internal utilities and pipelines (utils-pipe.R, globals.R)
b. Example Data & Vignettes (inst/ directory)
– inst/extdata: example CSV, TXT, RData files used in examples/tests
– inst/reports & inst/sandpit: reproducible R Markdown reports and scripts
c. Documentation Site (pkgdown)
– pkgdown config (_pkgdown.yml, pkgdown/extra.css)
– index.md, vignettes/*.Rmd
d. Testing Suite (tests/)
– testthat scripts that invoke core functions against sample data
e. Metadata & Build Files
– DESCRIPTION, NAMESPACE, CITATION, LICENSE, NEWS.md
– R-project file (TwoSampleMR.Rproj), .Rbuildignore, .lintr
f. CI/CD Pipelines (.github/workflows)
– check-full.yaml: run R-CMD-check on multiple platforms
– test-coverage.yaml: generate coverage report
– pkgdown.yaml: build and deploy website
g. External Services
– IEU OpenGWAS API (data source)
– Zenodo (DOI badge)
– GitHub (source repo, Actions)
– R-Universe (package distribution)
Relationships & data flows
• User calls exported functions in Core R Library → Library fetches data via OpenGWAS API → transforms & harmonises data → runs MR methods → returns results or plots.
• Core Library functions read example inst/extdata for internal cross-checks or vignettes.
• Testing Suite invokes Core Library functions using inst/extdata; reports pass/fail to CI.
• Vignettes and inst/reports use Core Library to generate HTML/PDF outputs; served via pkgdown site.
• GitHub Actions orchestrate:
– R-CMD check → fails/passes status back to GitHub PR
– Test coverage tool → updates Codecov badge
– pkgdown build → publishes HTML site to GitHub Pages or R-Universe
Architectural patterns & design principles
• Modular functional design: each analytical step is a separate function (e.g., mr_ivw, mr_egger).
• Directory‐by‐concern: R/, man/, tests/, vignettes/, inst/, pkgdown/
• CI/CD as first‐class citizens: every push triggers checks, coverage, docs.
• Reproducibility via vignettes and inst/sandpit examples.