| name | replication-package |
| description | Create reproducible replication packages using rix/nix for R projects. Use when setting up project environments, preparing code for journal submission, or ensuring computational reproducibility. Covers rix, nix-shell, Makefile pipelines, and DCAS-compliant documentation. |
Replication Package with rix/nix
Initial Setup
Install nix
sh <(curl -L https://nixos.org/nix/install) --daemon
sudo systemctl restart nix-daemon
Install cachix for faster builds
nix-env -iA cachix -f https://cachix.org/api/v1/install
cachix use rstats-on-nix
Project Environment Setup
generate_env.R
library(rix)
rix(
r_ver = "4.3.2",
r_pkgs = c(
"data.table",
"tidyverse",
"here",
"fixest",
"did",
"grf",
"rdrobust",
"sf",
"spdep",
"spatialreg",
"modelsummary",
"kableExtra",
"ggplot2",
"patchwork",
"furrr",
"tictoc"
),
git_pkgs = list(
list(
package_name = "concordance",
repo_url = "https://github.com/insongkim/concordance",
commit = "HEAD"
)
),
system_pkgs = c("quarto"),
ide = "none",
project_path = ".",
overwrite = TRUE
)
Build and enter environment
nix-build
nix-shell
nix-shell --run "R"
Makefile for Pipeline
.PHONY: all clean data analysis paper
all: paper
data/build/01_clean_data/analysis.rds: code/build/01_clean_data/01_clean.R data/raw/*.csv
nix-shell --run "Rscript code/build/01_clean_data/01_clean.R"
output/01_main_reg/tables/main_results.tex: code/analysis/01_main_reg/01_baseline.R data/build/01_clean_data/analysis.rds
nix-shell --run "Rscript code/analysis/01_main_reg/01_baseline.R"
data: data/build/01_clean_data/analysis.rds
analysis: output/01_main_reg/tables/main_results.tex
paper: output/paper/paper.pdf
output/paper/paper.pdf: output/paper/paper.qmd analysis
nix-shell --run "quarto render output/paper/paper.qmd"
clean:
rm -f data/build/*/*.rds
rm -f output/*/tables/*.tex
rm -f output/*/figures/*.pdf
README Template (DCAS-compliant)
See references/readme-template.md for the full template. Key sections:
- Data Availability Statement: Source, access, licenses
- Computational Requirements: Hardware, software, runtime
- Description of Programs: What each script does
- Instructions: Step-by-step replication guide
- Output List: Map outputs to paper tables/figures
Folder Structure
Note: Only code/ lives in GitHub. data/ and output/ live on Dropbox (symlinked into the project). For replication packages, all files are assembled into a self-contained directory.
project/
├── .here # Project root marker
├── .gitignore
├── Makefile
├── README.md
├── generate_env.R
├── default.nix # Generated by rix (gitignored)
│
├── code/ # In GitHub
│ ├── build/
│ │ └── 01_clean_data/
│ │ └── 01_clean.R
│ └── analysis/
│ └── 01_main_reg/
│ └── 01_baseline.R
│
├── data/ # On Dropbox (symlinked)
│ ├── raw/ # Original data
│ └── build/ # Intermediate data (numbered by issue)
│ └── 01_clean_data/
│
└── output/ # On Dropbox (symlinked)
├── 01_main_reg/ # Numbered by issue
│ ├── tables/
│ └── figures/
├── paper/ # NOT numbered
└── slides/ # NOT numbered
Symlinks for Data and Output
ln -s ~/Dropbox/Projects/MyProject/data data
ln -s ~/Dropbox/Projects/MyProject/output output
.gitignore
# Data and output live on Dropbox, not in git
data/
output/
# Nix
result
default.nix
# R
.Rhistory
.RData
.Rproj.user/
# OS
.DS_Store
Verification Checklist
Before submission: