Docs menu
- Home
- Docs
- Reproducibility checks
- Reproducibility & Entry Points
Entry points and hard-coded paths in research code
When train.py, train_new.py and run.sh sit side by side and paths point to your home folder, newcomers have to guess. Give them one documented route to every result.
Last updated
In your report
- Area
- Execution
- Check
- Reproducibility & Entry Points
Why it matters
Research repositories grow around one laptop: analysis_v2.py next to analysis_final.py, data under /Users/…, and a figure that needs three scripts in an order nobody wrote down.
In a study of R code from Harvard Dataverse, automatic code cleaning fixed all errors caused by setwd() (Trisovic et al., 2022). “For every result, keep track of how it was produced” is rule 1 of the Ten Simple Rules for Reproducible Computational Research.
What good looks like
- Paths built from the project root or read from a config file, never
/Users/…orC:\…. - One command per result, collected in a
Makefile,Snakefile, Nextflow pipeline orrun.sh. - A README that walks from downloaded data to every figure and names the script to use where several exist.
- Raw data kept read-only; every intermediate file is regenerated by a script.
- A quick run on a small subset of the data that confirms the setup before the full analysis.
How to fix it
Python. Resolve paths from the project root and let the data location be overridden:
from pathlib import Path
import os
ROOT = Path(__file__).resolve().parents[1] # repository root, from src/pipeline.py
DATA = Path(os.environ.get("DATA_DIR", ROOT / "data"))
counts = DATA / "raw" / "counts.h5ad"R. The here package builds paths from the project root. Use it instead of setwd():
here::i_am("analysis/figure2.R")
counts <- readr::read_tsv(here::here("data", "raw", "counts.tsv"))One entry point. A Makefile records the order of steps and doubles as the smoke test:
all: results/table1.csv results/figure2.pdf
results/table1.csv: data/processed/cohort.parquet
python -m analysis.table1 --out $@
results/figure2.pdf: results/table1.csv analysis/figure2.R
Rscript analysis/figure2.R
smoke:
python -m analysis.table1 --subsample 0.01 --out /tmp/table1_smoke.csvRelated
See this check on your repository
Every analysis reports findings for this check, with file references and suggested fixes.