claude-r
Connects Claude Code or OpenCode to RStudio to execute R scripts, analyze data, and create visualizations.
Install
mkdir -p .claude/skills/claude-r && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/14752" && unzip -o skill.zip -d .claude/skills/claude-r && rm skill.zipInstalls to .claude/skills/claude-r
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Execute R code through RStudio via MCP. Use for R programming tasks, statistical analysis, data visualization, or setting up/troubleshooting the RStudio integration with Claude Code or OpenCode.Key capabilities
- →Execute R code and return text output
- →Generate plots from R code as PNG images
- →Query R environment for packages, variables, or version
- →Retrieve the currently open file in RStudio
- →Modify code sections in the active RStudio document
- →Set up R and its dependencies
How it works
This skill connects an AI assistant to RStudio, allowing it to generate and execute R code through an MCP server. RStudio acts as the execution engine, displaying results.
Inputs & outputs
When to use claude-r
- →Executing R code for statistical analysis
- →Generating data visualizations using ggplot2
- →Querying installed R packages and workspace variables
- →Troubleshooting RStudio integrations for AI coding assistants
About this skill
Claude-R - Execute R through RStudio
Connect an AI coding assistant (Claude Code or OpenCode) to RStudio, enabling agentic R programming. RStudio acts as the execution engine; the assistant generates and runs the code.
OpenCode discovers this skill from .claude/skills/ just like Claude Code (docs). The MCP config is written to .mcp.json (Claude Code) or opencode.jsonc (OpenCode).
Note: All commands in this document assume the working directory is the project root.
Quick Start
Prerequisites Check
Verify RStudio server is running:
uv run .claude/skills/claude-r/scripts/check_r_connection.py
# or with system Python (if httpx installed)
python .claude/skills/claude-r/scripts/check_r_connection.py
If not running:
- Open RStudio
- File → New Project → Existing Directory → select the project folder → Create Project
- If
.Rprojalready exists: File → Open Project → select your.Rprojfile → Open
- If
- Run:
library(ClaudeR) - Run:
claudeAddin() - Click "Start Server" in Viewer pane
Basic Usage
Execute R code:
x <- 1:10
mean(x)
Generate plots:
library(ggplot2)
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point(size = 3) +
theme_minimal()
Available MCP Tools
execute_r
Execute R code and return text output.
execute_r_with_plot
Execute R code that generates graphics. Returns PNG image.
get_r_info
Query R environment:
what: "packages"- Installed packageswhat: "variables"- Workspace objectswhat: "version"- R versionwhat: "all"- Complete summary
get_active_document
Retrieve currently open file in RStudio.
modify_code_section
Modify code in active RStudio document by pattern or line range.
Setup and Installation
Step 1: Install R and Dependencies
bash .claude/skills/claude-r/scripts/setup_claude-r.sh
This installs:
- R via Homebrew
- System dependencies (harfbuzz, libtiff, libgit2, etc.)
- R packages (renv, devtools, ClaudeR)
Step 2: Configure MCP Client
-
Get the MCP server script path:
Rscript -e 'cat(system.file("scripts/persistent_r_mcp.py", package="ClaudeR"))' -
Determine which client the user is using. If unclear, ask the user.
-
Ask the user which Python environment to use for running the MCP server. Options:
uv(recommended — no pre-install needed)- System Python (
python3) - Other (conda, venv, pyenv, etc.)
If the user chooses a custom environment, adapt the command/path accordingly. The MCP server script requires
httpxandmcppackages. -
Register the MCP server:
Claude Code (
claude mcp addwrites to.mcp.json):With
uv:claude mcp add -s project r-studio -- \ uv run --with httpx --with mcp python <script path>With system Python (install
httpxandmcpfirst):python3 -m pip install --user httpx mcp claude mcp add -s project r-studio -- \ python3 <script path>With custom environment (example: conda):
conda install httpx mcp claude mcp add -s project r-studio -- \ /path/to/conda/env/bin/python <script path>Docs: https://code.claude.com/docs
OpenCode (write
opencode.jsoncin the project root):With
uv:{ "$schema": "https://opencode.ai/config.json", "mcp": { "r-studio": { "type": "local", "command": [ "uv", "run", "--with", "httpx", "--with", "mcp", "python", "<script path>" ], "enabled": true } } }With system Python:
{ "$schema": "https://opencode.ai/config.json", "mcp": { "r-studio": { "type": "local", "command": ["python3", "<script path>"], "enabled": true } } }With custom environment (adapt command to the Python binary path):
{ "$schema": "https://opencode.ai/config.json", "mcp": { "r-studio": { "type": "local", "command": ["/path/to/env/bin/python", "<script path>"], "enabled": true } } }Docs: https://opencode.ai/docs
Step 3: Start R Server
Relay the following instructions to the user exactly as written:
- Open RStudio
- File → New Project → Existing Directory → select the project folder → Create Project
- If
.Rprojalready exists: File → Open Project → select your.Rprojfile → Open
- If
- Run
library(ClaudeR)in the R console - Run
claudeAddin()in the R console - Click "Start Server" in the Viewer pane
Step 4: Verify
Claude Code: Run /mcp in Claude Code, or claude mcp list from the terminal. "r-studio" should show "connected".
OpenCode: Run /mcps in OpenCode, or opencode mcp list from the terminal. "r-studio" should show "connected".
If the server does not appear or shows "failed", ask the user to restart the client and try again. If the issue persists, see references/troubleshooting.md.
Architecture
Three-layer system:
- AI Coding Assistant (Claude Code or OpenCode): Natural language interface
- MCP Server: Python bridge (stdio ↔ HTTP)
- ClaudeR HTTP Server: R execution in RStudio (port 8787)
RStudio acts passively. Users interact with the assistant, which generates and executes R code. RStudio's Environment, Plots, and Console panes show results.
See references/architecture.md for details.
Troubleshooting
If R code execution fails, check connection:
uv run .claude/skills/claude-r/scripts/check_r_connection.py
Common issues:
- RStudio server not running
- MCP configuration incorrect
- Python dependencies missing
See references/troubleshooting.md for complete guide.
Key Features
- State persistence: R session persists across executions
- RStudio integration: View variables, plots, and console in RStudio
- Agentic: Generate and execute R code through conversation
Limitations
- Single-threaded: Sequential execution only
- Local only: Server binds to localhost
- RStudio required: Must be running with server active
- No streaming: Results return after complete execution
Resources
- Troubleshooting Guide - Connection issues, setup errors
- Architecture - System design and data flow
- Setup Script - Automated installation
- Connection Checker - Verify server status
- ClaudeR GitHub - Original project
Client Documentation
When not to use it
- →When RStudio is not running or connected
- →When the task does not involve R programming or statistical analysis
- →When the user does not want to interact with R through an AI assistant
Prerequisites
Limitations
- →Execution is single-threaded
- →The server binds to localhost only
- →RStudio must be running with the server active
How it compares
This skill enables an AI assistant to directly interact with an RStudio instance, automating R code execution and environment queries, unlike manual R programming.
Compared to similar skills
claude-r side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| claude-r (this skill) | 0 | 6mo | Review | Advanced |
| streamlit | 86 | 9mo | No flags | Intermediate |
| openalex-database | 48 | 7mo | Review | Intermediate |
| data-storytelling | 47 | 2mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
streamlit
sverzijl
When working with Streamlit web apps, data dashboards, ML/AI app UIs, interactive Python visualizations, or building data science applications with Python
openalex-database
davila7
Query and analyze scholarly literature using the OpenAlex database. This skill should be used when searching for academic papers, analyzing research trends, finding works by authors or institutions, tracking citations, discovering open access publications, or conducting bibliometric analysis across 240M+ scholarly works. Use for literature searches, research output analysis, citation analysis, and academic database queries.
data-storytelling
wshobson
Transform data into compelling narratives using visualization, context, and persuasive structure. Use when presenting analytics to stakeholders, creating data reports, or building executive presentations.
csv-data-summarizer
coffeefuelbump
Analyzes CSV files, generates summary stats, and plots quick visualizations using Python and pandas.
umap-learn
K-Dense-AI
UMAP dimensionality reduction. Fast nonlinear manifold learning for 2D/3D visualization, clustering preprocessing (HDBSCAN), supervised/parametric UMAP, for high-dimensional data.
data-visualization
anthropics
Create effective data visualizations with Python (matplotlib, seaborn, plotly). Use when building charts, choosing the right chart type for a dataset, creating publication-quality figures, or applying design principles like accessibility and color theory.