R Data Analysis

VerifiedCaution

End-to-end R data analysis following project conventions (here, arrow, fixest, modelsummary), including code review and publication-ready outputs.

Sby Skills Guide Bot
Data & AIAdvanced
8/6/2026
Claude Code
#r#econometrics#reproducible-research#data-analysis#fixest

Recommended for

Automated summary

Runs an end-to-end R data analysis for the sewage project, writing scripts that follow project conventions and producing publication-ready tables and figures.

Strengths

  • Automatically applies the project's R conventions: here::here(), native pipe, arrow/parquet, fixest, and modelsummary.
  • Covers the full cycle: context gathering, script writing, code review, execution, and results summary.
  • Generates standardized outputs: LaTeX tables, PDF/PNG figures, and RDS regression objects.
  • Uses existing scripts and manuscript documentation to keep the analysis consistent with ongoing work.

Limitations

  • Tightly coupled to the sewage project: paths, subdirectories, and conventions are hard-coded.
  • Assumes the R environment, datasets, and required packages are already installed and accessible.
  • The built-in code review does not replace econometric validation or independent verification of results.
When to use it

Use when you need to write or modify an R analysis script for the sewage project, estimate a specification, or generate tables and figures from final datasets.

When not to use it

Avoid for R analyses outside the sewage project, for upstream data cleaning in the pipeline, or when the project data and environment are unavailable.

Security analysis

Caution
Quality score90/100

The skill is a legitimate data-analysis workflow with no malicious exfiltration, destructive commands, obfuscation, or safety-disabling instructions. However, it grants Bash and can execute generated R scripts, and it permits Agent use without constraints; the hardcoded local path is a minor privacy/portability issue. These justify caution rather than risky.

Findings
  • •Allows Bash and instructs running generated R scripts via Rscript, which executes arbitrary code with the user's permissions.
  • •Contains a hardcoded absolute local path (/Users/jacopoolivieri/...) that exposes a username/project path and is non-portable.
  • •Allows the Agent tool without describing how or when subagents should be used, expanding execution capability beyond the documented workflow.
  • •Writes and edits files and outputs without explicit overwrite/confirmation safeguards.
How this analysis is made

Examples

Hedonic regression
Run a hedonic regression of log_price on spill_count with LSOA and year-quarter fixed effects, then export a modelsummary table to output/tables/hedonic_main.tex and save the model RDS.
Repeat-sales specification
Add a repeat-sales specification to the analysis using data/final/repeat_sales.parquet, follow the project conventions, and produce the regression table and figure.
Descriptive script
Write an R script in scripts/R/09_analysis/01_descriptive/ to create scatter plots and a map from data/final, using here and arrow, and save outputs to output/figures/.

name: data-analysis description: End-to-end R data analysis for the sewage project. Writes analysis scripts following project conventions (here::here, arrow/parquet, fixest, modelsummary, native pipe), runs code review, and produces publication-ready tables and figures. This skill should be used when asked to "run an analysis", "estimate the model", "add a specification", or "write an R script". argument-hint: "[dataset path, analysis goal, or specification description]" allowed-tools: ["Read", "Grep", "Glob", "Write", "Edit", "Bash", "Agent"]

Data Analysis

Run an end-to-end data analysis following sewage project conventions.

Input: $ARGUMENTS — a dataset path, analysis goal description, or specification to estimate.


Project-Specific Context

Analysis Organisation

Scripts in scripts/R/09_analysis/ by approach:

  • 01_descriptive/ — Maps, scatter plots, Google Trends
  • 02_hedonic/ — Cross-sectional hedonic regressions
  • 03_repeat_sales/ — Repeat-transaction regressions
  • 04_long_difference/ — 250m grid-level long differences
  • 05_news/ — DiD and event studies with media coverage
  • 06_upstream_downstream/ — Directional spillover
  • 07_dry_spills/ — Dry spill analysis

Datasets

  • data/final/ — Analysis-ready datasets
  • data/processed/ — Intermediate pipeline outputs (parquet)
  • All data loaded via arrow::read_parquet() or arrow::open_dataset()

Output Destinations

  • Tables: output/tables/*.tex (modelsummary → LaTeX with tabularray)
  • Figures: output/figures/*.pdf or *.png
  • Regression objects: output/regs/*.rds
  • HTML interactive: output/html_plots/

Required R Conventions

  • here::here() for all paths
  • Native pipe |>
  • fixest::feols() for regressions with vcov = "hetero"
  • modelsummary for table output (tabularray format, [H] placement)
  • arrow for parquet I/O
  • snake_case naming
  • forcats::as_factor() for factors

Workflow

Step 1: Context Gathering

  1. Understand the analysis goal from $ARGUMENTS
  2. Read existing analysis scripts in the relevant subdirectory for patterns
  3. Read scripts/R/utils/spill_aggregation_utils.R if spill metrics are involved
  4. Check data/final/ for available datasets
  5. Read the relevant manuscript section in docs/overleaf/ if the analysis feeds into the paper

Step 2: Write Analysis Script

Follow the analysis script structure:

# ================================================================
# [Descriptive Title]
# Purpose: [What this script does]
# Inputs: [Data files]
# Outputs: [Figures, tables, RDS files]
# ================================================================

# === 1. Setup ============================================

library(tidyverse)
library(fixest)
library(modelsummary)
library(arrow)
library(here)

# === 2. Data Loading =====================================

df <- read_parquet(here("data", "final", "dataset.parquet"))

# === 3. Main Analysis ====================================

model <- feols(
  log_price ~ spill_count | lsoa + year_quarter,
  data = df,
  vcov = "hetero"
)

# === 4. Tables and Figures ================================

modelsummary(
  list("Main" = model),
  output = here("output", "tables", "table_name.tex"),
  fmt = 3
)

# === 5. Export ============================================

saveRDS(model, here("output", "regs", "model_name.rds"))

Step 3: Code Review

After writing the script, review it against the 9 categories from /review-r:

  • Script structure, console hygiene, reproducibility
  • Function design, figure quality, data persistence
  • Comments, error handling, polish

Fix any Critical or Major issues before presenting.

Step 4: Run the Script

If the user wants execution:

cd /Users/jacopoolivieri/Library/CloudStorage/Dropbox/01_projects/sewage
Rscript scripts/R/09_analysis/[subdir]/[script_name].R

Step 5: Present Results

  1. Results summary — Key estimates with SEs and economic interpretation
  2. Script created — Path and description
  3. Output files — Tables and figures generated
  4. Code review notes — Any conventions to flag
  5. TODO items — Missing data, additional specifications needed

Principles

  • Reproduce, don't guess. If a specific regression is requested, implement exactly that.
  • Strategy alignment. If an analysis feeds into a manuscript section, the code must implement what the paper claims.
  • Publication-ready output. Tables and figures should be directly includable in the paper.
  • Follow existing patterns. Read neighbouring scripts in the same subdirectory for style consistency.
  • Save everything. Every regression object saved as RDS, every table as LaTeX, every figure as PDF.

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/r-data-analysis-msh3ut3a/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/r-data-analysis-msh3ut3a' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/r-data-analysis-msh3ut3a/download' --output '.skill-downloads/r-data-analysis-msh3ut3a/SKILL.md.part' && mv '.skill-downloads/r-data-analysis-msh3ut3a/SKILL.md.part' '.skill-downloads/r-data-analysis-msh3ut3a/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/r-data-analysis-msh3ut3a/SKILL.md' && test -s '.skill-downloads/r-data-analysis-msh3ut3a/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/data-analysis' && cp -R '.skill-downloads/r-data-analysis-msh3ut3a' '.claude/skills/data-analysis'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/r-data-analysis-msh3ut3a'

openskills read 'r-data-analysis-msh3ut3a'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/r-data-analysis-msh3ut3a/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills