Назад към всички

run-r-analysis

// Execute R scripts and RMarkdown files in existing projects, handle parameterized analyses, and return results, tables, and plots.

$ git log --oneline --stat
stars:1,933
forks:367
updated:March 4, 2026
SKILL.mdreadonly
SKILL.md Frontmatter
namerun-r-analysis
descriptionExecute R scripts and RMarkdown files in existing projects, handle parameterized analyses, and return results, tables, and plots.

Run R Analysis

A specialized sub-skill for executing R analyses in existing research projects and generating comprehensive outputs.

Overview

This sub-skill runs R scripts, RMarkdown documents, and Quarto reports within an existing R project structure. It captures all outputs including console results, plots, tables, and rendered reports.

Use this sub-skill when the user wants to:

  • Execute an R script in a project
  • Generate an R Markdown or Quarto report
  • Run parameterized analyses with different inputs
  • Capture and return analysis outputs

What This Sub-Skill Does

When invoked, this sub-skill will:

  1. Activate project environment

    • Load renv environment if present
    • Set working directory to project root
    • Source .Rprofile if available
  2. Execute analysis script

    • Run specified R script
    • Capture console output
    • Track generated files
    • Monitor for errors and warnings
  3. Generate reports

    • Render R Markdown to HTML/PDF
    • Render Quarto documents
    • Include all figures and tables
    • Return rendered report path
  4. Return results

    • Console output and messages
    • Paths to generated files
    • Summary statistics
    • Error messages if any

Example User Requests

  • "Run analysis.R and show me the results"
  • "Execute the differential expression analysis in my RNA-seq project"
  • "Render the report and return the HTML file"
  • "Run the analysis with different parameters"
  • "Generate all plots from my analysis script"

Supported File Types

File TypeExecution MethodOutput
.R scriptssource()Console output + generated files
.Rmdrmarkdown::render()HTML/PDF/Word document
.qmdquarto::quarto_render()HTML/PDF/Word document
Parameterized scriptswith parametersMultiple outputs

Execution Workflow

1. Verify project structure exists
   ↓
2. Activate renv environment (if present)
   ↓
3. Load required packages
   ↓
4. Execute analysis script
   ↓
5. Capture outputs
   ↓
6. Return results summary

Output Handling

Console Output

All print statements, messages, and warnings are captured and returned.

Generated Files

  • Figures: results/figures/*.pdf, *.png, *.svg
  • Tables: results/tables/*.csv, *.tsv
  • Models: results/models/*.rds
  • Reports: reports/*.html, *.pdf

Error Handling

  • Script errors are reported with line numbers
  • Missing packages are identified
  • File path issues are diagnosed
  • Suggestions for fixes are provided

Parameters

ParameterDescriptionDefault
script_pathPath to R script or Rmd fileRequired
working_dirProject root directoryCurrent directory
render_reportAlso render Rmd/qmd if presenttrue
output_formatReport format (html, pdf, all)html
paramsNamed list for parameterized reportsNULL

Example Usage

Basic Script Execution

User: Run the analysis script in my project.

Skill actions:

# Set working directory
setwd("my-project")

# Activate renv
renv::activate()

# Source analysis script
source("scripts/01_analysis.R")

# Report outputs
# - results/tables/statistics.csv created
# - results/figures/pca_plot.pdf created
# - results/models/regression_model.rds created

Parameterized Report

User: Run the report with dataset='variant2'.

Skill actions:

rmarkdown::render(
  "reports/report.Rmd",
  params = list(dataset = "variant2"),
  output_format = "html_document"
)
# Output: reports/report_variant2.html

Quarto Report

User: Render the Quarto document to PDF.

Skill actions:

quarto::quarto_render(
  "reports/analysis.qmd",
  output_format = "pdf"
)
# Output: reports/analysis.pdf

Common Output Patterns

Analysis TypeExpected Outputs
Differential ExpressionVolcano plots, MA plots, DEG tables
PCAPCA plots, loadings, explained variance
ClusteringDendrograms, heatmaps, cluster assignments
RegressionDiagnostic plots, coefficient tables, predictions
Time SeriesForecast plots, residuals, accuracy metrics

Notes

  • Working directory is always set to project root
  • Relative paths in scripts work correctly
  • renv ensures correct package versions
  • All outputs are tracked and reported
  • Long-running scripts show progress updates

Related Sub-Skills

  • create-project: Set up new projects before running analyses
  • debug-env: Troubleshoot environment issues before execution