pedrohcgs/data-analysis
End-to-end R data analysis pipeline — exploration → cleaning → regression → publication-ready tables and figures. Use when user says "analyze this dataset", "run a regression on X", "explore this CSV", "full analysis workflow", "get me summary stats and a regression", or points at a `.csv`/`.rds`/`.dta` and asks for empirical results. Produces numbered R scripts in `scripts/R/` and outputs to `scripts/R/_outputs/`.
npx skills add https://github.com/pedrohcgs/claude-code-my-workflow --skill data-analysis
Run an end-to-end data analysis in R: load, explore, analyze, and produce publication-ready output.
Input: $ARGUMENTS — a dataset path (e.g., data/county_panel.csv) or a description of the analysis goal (e.g., "regress wages on education with state fixed effects using CPS data").
.claude/rules/r-code-conventions.mdscripts/R/ with descriptive namesoutput/saveRDS() for every computed object — Quarto slides may need them.claude/rules/)Before writing any analysis code, produce a Pre-Flight Report showing you read the inputs. This prevents the common failure mode where the agent hallucinates variable names or skips project conventions.
Output block (in your response to the user, before Phase 1):
## Pre-Flight Report
**Dataset:** [path]
- Variables found: [list from head()/names()]
- Rows: [count]
- Key types: [e.g., "outcome=numeric, treatment=binary, state=factor"]
- Missing-data summary: [% missing per key var]
**Project conventions read:**
- `.claude/rules/r-code-conventions.md` — [one-line summary of most relevant rule]
- `.claude/rules/content-invariants.md` — [INV-9, INV-10, INV-11, INV-12 applicable]
**Task interpretation:** [one sentence restating what the user asked for]
**Plan:** [3-5 bullet outline of the R script structure]
If any input cannot be read (missing file, unreadable format), stop and ask the user before proceeding.
library(), never require())r-code-conventions.md), e.g. set.seed(20260415) (INV-9)Generate diagnostic outputs:
summary(), missingness rates, variable typesSave all diagnostic figures to output/diagnostics/.
Based on the research question:
fixest for panel data, lm/glm for cross-sectionTables:
modelsummary for regression tables (preferred) or stargazer.tex for LaTeX inclusion and .html for quick viewingFigures:
ggplot2 with project themebg = "transparent" for Beamer compatibilityggsave(width = X, height = Y).pdf and .pngsaveRDS() for all key objects (regression results, summary tables, processed data)output/ subdirectories as needed with dir.create(..., recursive = TRUE)Delegate to the r-reviewer agent:
"Review the script at scripts/R/[script_name].R"
Follow this template:
# ============================================================
# [Descriptive Title]
# Author: [from project context]
# Purpose: [What this script does]
# Inputs: [Data files]
# Outputs: [Figures, tables, RDS files]
# ============================================================
# 0. Setup ----
library(tidyverse)
library(fixest)
library(modelsummary)
set.seed(20260415) # YYYYMMDD per r-code-conventions.md (INV-9)
dir.create("output/analysis", recursive = TRUE, showWarnings = FALSE)
# 1. Data Loading ----
# [Load and clean data]
# 2. Exploratory Analysis ----
# [Summary stats, diagnostic plots]
# 3. Main Analysis ----
# [Regressions, estimation]
# 4. Tables and Figures ----
# [Publication-ready output]
# 5. Export ----
# [saveRDS for all objects, ggsave for all figures]
For regressions, simulations, or bootstrap loops that take more than a couple of minutes, launch via Bash with run_in_background: true and then use Anthropic's Monitor tool to stream R stdout into the conversation in real time. Pattern:
Rscript scripts/R/03_analyze.R with run_in_background: true. Capture the bash_id.bash_id until a milestone fires (e.g., Coefficients table written, or process exit).This avoids the polling-loop anti-pattern (sleep 30; check; sleep 30; check) and avoids burning cache on idle waits. Especially useful when paired with the Cost-Conscious Parallelism section of the guide.
Take pedrohcgs/data-analysis from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.