Guiding principles
Before picking a folder structure, it helps to know what problem it’s actually solving. A good project organization system serves three principles:
- Reproducibility. You (or another scientist) should be able to repeat your analysis.
- Maintainability. You should be able to jump back into editing your analysis, even if you haven’t looked at it in months.
- Collaboration. You should be able to share your analysis methods and results with others.
Those principles sound nice, but how do we actually implement them in practice? You’ve probably been told to “comment your code,” but that’s insufficient guidance. Inspired by the British Ecological Society’s A Guide to Reproducible Code in Ecology and Evolution, this page describes a folder organization system you can use while you figure out what works best for you and your collaborators.
Folder organization
It’s less important which system you pick than it is to stick with it. This course uses a modified version of the system outlined by Anna Krystalli in A Guide to Reproducible Code in Ecology and Evolution.
Here’s an example of what the folder organization for an analysis could look like.
analysis
├── 1_clean_data.R
├── data
│ └── streamflow.csv
├── docs
│ └── flow-analysis.html
├── figs
│ ├── annual-flow.png
│ └── predicted-flow.png
├── output
│ └── streamflow-clean.rds
├── paper
│ └── paper.qmd
├── R
│ └── util.R
├── REAMDE.md
├── reports
│ └── flow-analysis.qmd
└── scratch
└── explore-metadata.R
Most of the file names are placeholder examples; it’s the folder names that are key.
Folder purpose and use
data/contains all input data (and metadata) used in the analysis.paper/contains the manuscript.figs/contains figures generated by the analysis.output/contains any type of intermediate or output files (e.g. processed datasets, models, etc.). On larger projects, you might separate this further into something likecleaned-data/.R/contains R scripts with function definitions.reports/contains Quarto files that document the analysis or report on results.docs/contains the rendered versions of the reports.scratch/contains early prototypes and other code you don’t fully understand yet.
Important files
REAMDE.mdprovides a high-level overview of the project.- Top-level scripts (e.g.,
1_clean_data.R) live in the project root. These scripts should run before the Quarto documents inreports/render. They’re useful for anything you want done in advance, such as data cleaning or fitting large models that take a long time to run.
Benefits
The biggest benefit of adopting a system like this is the cognitive space it frees up. Any brainpower you were spending figuring out where to put a file — or where to find one — can now go toward your actual science. This is also true for your collaborators!
Separation of data and code
This system makes it easy to keep raw data protected. Never touch your raw data. Ever. Seriously (Broman and Woo 2018). Put your raw data and all the metadata you need to use it in data/, and make any edits you need in code. Save the changed versions out to output/.
It might seem easier to open up Excel, add a column, or fix a typo by hand. Don’t be tempted; only madness lies down that path. If an edit isn’t recorded in a script, nobody (including future you) can verify what changed or why.
GitHub for project management
This system promotes using GitHub for project management. For example, putting rendered Quarto reports in the docs/ folder streamlines using GitHub Pages to share your analysis as a website.