Skill: jackkuo666/creating-r-research-projects (version 0.1.0)

--- name: creating-r-research-projects description: Set up a reproducible R research workspace, install required packages, run statistical or bioinformatics analysis, and generate publication-ready reports and visualizations. --- # Creating R Research Projects This skill helps create and manage a complete R-based research analysis workflow. It is designed for scientific computing, statistical modeling, bioinformatics, and data visualization tasks. Use this skill when the user wants to: - Analyze datasets using R - Perform statistical tests or modeling - Run bioinformatics or omics analysis in R - Generate plots, figures, or reports - Create a reproducible R project structure - Install and manage R package dependencies --- ## What This Skill Does When activated, this skill will: 1. **Create a structured R project** - `data/` for raw and processed data - `scripts/` for analysis code - `results/` for outputs - `reports/` for R Markdown or Quarto reports 2. **Set up environment** - Initialize `.Rproj` (if using RStudio) - Create `renv` environment for reproducibility - Install required CRAN/Bioconductor packages 3. **Generate analysis scripts** - Data loading and cleaning - Statistical analysis or modeling - Visualization with `ggplot2` - Save outputs (CSV, plots, model summaries) 4. **Create a report** - R Markdown / Quarto document - Includes methods, results, and figures - Render to HTML or PDF --- ## Example User Requests That Should Trigger This Skill - "Use R to analyze this CSV and generate plots" - "Run differential expression analysis in R" - "Create a statistical report for this dataset" - "Build an R project for microbiome analysis" - "Fit a regression model in R and summarize results" --- ## Example Workflow **User:** Analyze this gene expression dataset and produce figures. **Skill actions:** - Create project structure - Install `tidyverse`, `DESeq2`, `ggplot2` - Write analysis script - Generate PCA plot and volcano plot - Produce an HTML report --- ## Tools & Packages Commonly Used | Purpose | R Packages | |--------|------------| | Data wrangling | tidyverse, data.table | | Visualization | ggplot2, patchwork | | Statistics | stats, lme4, survival | | Bioinformatics | Bioconductor packages (DESeq2, edgeR, limma) | | Reporting | rmarkdown, quarto | | Reproducibility | renv | --- ## Notes - Prefer reproducible workflows (`renv`, scripted analysis) - Avoid interactive-only steps unless requested - All outputs should be saved to files, not just printed to console

path: README.md
content: # Creating R Research Projects

A Claude Code skill for creating reproducible, publication-ready R research projects with proper structure, package management, and automated reporting.

## Features

- 📁 **Standardized Project Structure** - Organized directories for data, scripts, results, and reports
- 📦 **Package Management** - Uses `renv` for reproducible R environments
- 📊 **Automated Analysis** - Template scripts for common statistical and bioinformatics tasks
- 📄 **Publication Reports** - R Markdown and Quarto templates for professional reports
- 🔄 **Version Control Ready** - Pre-configured `.gitignore` for R projects

## Quick Start

Invoke the skill by asking Claude to create an R research project:

```
Create an R project for analyzing my gene expression data
```

```
Set up a statistical analysis project in R for the clinical trial data
```

```
Build a reproducible R workflow for microbiome analysis
```

## Project Structure

When activated, this skill creates the following structure:

```
my-research-project/
├── data/
│   ├── raw/               # Original, immutable data files
│   └── processed/         # Cleaned, transformed data
├── scripts/               # Analysis and processing scripts
├── results/
│   ├── figures/           # Plots and visualizations
│   ├── tables/            # Summary tables
│   └── models/            # Saved model objects (.rds files)
├── reports/               # R Markdown/Quarto documents
├── docs/                  # Additional documentation
├── renv.lock              # Package version lock file
├── .Rproj                 # RStudio project file
└── README.md              # Project documentation
```

## Usage Examples

### Example 1: Gene Expression Analysis

```
Create an R project to analyze RNA-seq differential expression

The skill will:
- Create project structure
- Install DESeq2, tidyverse, ggplot2
- Generate analysis script with DESeq2 workflow
- Create PCA and volcano plot templates
- Set up Quarto report for results
```

### Example 2: Statistical Modeling

```
Build an R project for regression analysis on this dataset

The skill will:
- Set up project directories
- Install stats, lme4, broom packages
- Create modeling script template
- Generate diagnostic plot functions
- Create report template for model summary
```

### Example 3: Data Visualization Dashboard

```
Create an R visualization project for the sales data

The skill will:
- Initialize ggplot2, patchwork, scales
- Create plotting templates
- Set up multi-panel figure layouts
- Generate export functions for different formats
```

## Common Workflows

### Starting a New Project

```r
# Run the initialization script
source("templates/project_template.R")

# Or manually:
renv::init()
# Install packages as needed
renv::snapshot()  # Save package state
```

### Running Analysis

```r
# Set working directory
setwd("my-project")
renv::activate()  # Load project-specific library

# Run analysis
source("scripts/01_data_preparation.R")
source("scripts/02_analysis.R")

# Generate report
quarto::quarto_render("reports/report.qmd")
```

### Restoring on Another Machine

```r
setwd("my-project")
renv::restore()  # Install exact package versions
```

## Templates Included

| Template | Description |
|----------|-------------|
| `project_template.R` | Complete project initialization script |
| `analysis.R` | Standard analysis script template |
| `report.qmd` | Quarto report template |
| `renv.lock.example` | Example package lock file |

## Supported Analyses

This skill supports creating workflows for:

- **Differential Expression**: DESeq2, edgeR, limma
- **Statistical Tests**: t-tests, ANOVA, chi-square, Wilcoxon
- **Regression Models**: Linear, logistic, mixed-effects (lme4)
- **Time Series**: Forecasting, decomposition
- **Clustering**: PCA, t-SNE, UMAP, hierarchical clustering
- **Visualization**: ggplot2, patchwork, complex multi-panel figures

## Best Practices

1. **Never modify raw data** - Always work on copies in `data/processed/`
2. **Use `renv::snapshot()`** after installing new packages
3. **Script everything** - Avoid interactive-only analysis
4. **Save all outputs** - Plots, tables, and model objects
5. **Document with reports** - Use Quarto/R Markdown for reproducibility

## Requirements

- R >= 4.0.0
- renv package: `install.packages("renv")`
- (Optional) RStudio for `.Rproj` support
- (Optional) Quarto CLI for advanced reports

## License

MIT

## Contributing

Suggestions and improvements welcome! This skill is designed to be a template for reproducible R research workflows.


path: examples/README.md
content: # Example: Demo Statistical Analysis

This is a complete example demonstrating the R research project workflow.

## Project Structure

```
demo-analysis/
├── data/
│   └── raw/
│       └── sample_data.csv      # Sample dataset with control/treatment groups
├── scripts/
│   └── demo_analysis.R          # Complete analysis script
├── results/
│   └── figures/                  # Generated plots (after running)
└── reports/
    └── demo_report.qmd           # Quarto report template
```

## How to Run

### Option 1: Run the analysis script

```r
# Navigate to the example directory
setwd("examples/demo-analysis")

# Run the analysis
source("scripts/demo_analysis.R")
```

This will:
- Load the sample data
- Calculate descriptive statistics
- Perform a t-test
- Generate box plot and scatter plot
- Save results to `results/figures/`

### Option 2: Generate the report

```bash
cd examples/demo-analysis
quarto render reports/demo_report.qmd
```

This creates `reports/demo_report.html` with formatted results.

## Sample Data

The `sample_data.csv` contains simulated data with:
- 15 observations
- 2 groups (control, treatment)
- 3 numeric variables (value1, value2, value3)

## Analysis Workflow

1. **Load data** - Import CSV with `read_csv()`
2. **Summarize** - Group-wise statistics with `dplyr`
3. **Test** - t-test for group comparison
4. **Visualize** - ggplot2 box plots and scatter plots
5. **Report** - Quarto document combining code and narrative

## Expected Output

After running the analysis:

```
results/figures/
├── boxplot.png       # Box plot by group
└── scatterplot.png   # Correlation scatter plot

reports/
└── demo_report.html  # Formatted report (if rendered)
```

## Extending This Example

Try modifying the script to:
- Add more statistical tests (ANOVA, correlation)
- Create additional visualizations (violin plots, heatmaps)
- Include data transformation steps
- Add a methods section to the report


path: examples/demo-analysis/data/raw/sample_data.csv
content: id,group,value1,value2,value3
1,control,12.5,45.2,0.85
2,control,14.2,48.1,0.92
3,control,11.8,42.3,0.78
4,control,13.5,46.7,0.88
5,control,12.9,44.9,0.81
6,treatment,18.3,52.1,1.12
7,treatment,19.7,55.8,1.25
8,treatment,17.2,50.3,1.05
9,treatment,20.1,57.2,1.28
10,treatment,18.9,53.6,1.18
11,control,13.1,45.8,0.84
12,control,12.4,43.9,0.79
13,treatment,19.2,54.7,1.22
14,treatment,17.8,51.9,1.09
15,treatment,20.5,58.1,1.31


Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector: clean (LOW)