1  Organizing the Folders

Day-to-day analysis mixes two very different kinds of work.

If you do both in the same file, exploratory code and production code get tangled, and you end up asking yourself, “Which code produced the OR of 0.34 in the paper again?” So we split folders by role.

1.1 Overall folder layout

jcsm_project/
├─ _targets.R          the computation pipeline (Chapter 3)
├─ references.bib      references (exported from Paperpile etc.)
├─ data/
│   ├─ 00_raw/         raw data (never touched)
│   ├─ 01_interim/     intermediate data
│   └─ 02_processed/   analysis-ready data (everyone reads from here)
├─ analysis/           exploration and rough notes (may be messy, may be deleted)
├─ reports/            interim reports shown to others (supervisor, collaborators, meetings)
├─ manuscript/
│   └─ jcsm/           the paper (one folder per journal)
├─ scripts/            finalized processing (functions)
│   ├─ 01_fetch/       data retrieval / creation
│   ├─ 02_preprocess/  preprocessing
│   ├─ 04_analysis/    main models and numbers in the text
│   ├─ 05_output/      tables and figures for submission
│   ├─ checks/         citation checks, number diffs, etc. (Chapters 4 and 5)
│   └─ common/         shared settings and table formatting
├─ results/            snapshots of the numbers in the text (Chapter 5)
└─ output/             outputs (docx, figures, html)

1.2 The roles of the four layers

Folder What it is for How clean OK to delete?
analysis/ Exploration; try lots of things Messy is fine Yes
reports/ Interim reports for others Presentable Once the report is done
manuscript/ The paper Perfect No
scripts/ Finalized processing (functions) Clean No

1.2.1 analysis/: the place to explore

  • Start file names with the date (2026-11-20_model_explore.qmd). You can see at a glance what you tried and when
  • Inline code is fine. Ten candidate models lined up in one notebook is no problem
  • Delete notebooks you no longer need (git keeps the history)

1.2.2 reports/: interim reports for others

  • Progress reports to your supervisor, materials for meetings with collaborators, lab meeting slides, and so on
  • If you show an analysis/ notebook as is, people also see the models you discarded. Put a cleaned-up version for presentation here

1.2.3 manuscript/: the paper

  • No computation happens here. It only reads results computed by functions in scripts/ (Chapters 3 and 4)
  • One folder per journal (manuscript/jcsm/). If the paper is rejected and you submit elsewhere, copy the folder and change only the formatting

1.2.4 scripts/: finalized processing

  • Processing that you tried in analysis/ and decided to adopt is placed here as functions
  • Both analysis/ and manuscript/ call the functions here

1.3 The most important rule

ImportantOnly what has been moved to scripts/ goes into the paper
  • manuscript/ never reads qmd files in analysis/ (the paper would depend on messy code)
  • Never copy-paste code from analysis/ into manuscript/ (explained in Chapter 2)

The direction of dependencies looks like this. Arrows point in the direction of “reads”.

flowchart TB
  data[("data/02_processed")]
  scripts["scripts/<br/>finalized functions"]
  analysis["analysis/<br/>exploration"]
  reports["reports/<br/>interim reports"]
  manuscript["manuscript/<br/>paper"]
  analysis --> scripts
  reports --> scripts
  manuscript --> scripts
  analysis --> data
  scripts --> data
  manuscript -. "✕ does not read" .-> analysis

analysis/ and manuscript/ never read each other directly. Both read scripts/, so the same function produces the same numbers.

1.4 Preprocessing goes into scripts/ from the start

There is one exception. Preprocessing (handling of missing data, derived variables, exclusion criteria) is written in scripts/ from the very beginning.

If each analysis/ notebook does its own preprocessing, notebook A ends up excluding 12 people and notebook B 13. If every notebook reads the same data in data/02_processed/, that kind of discrepancy cannot happen.

1.5 Summary

  • Separate the place for trying things (analysis/) from the place for decided things (scripts/)
  • The paper (manuscript/) only reads results from scripts/
  • Write preprocessing in scripts/ from the start, so everyone reads the same processed data