# claude-r > 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. - Author: Naoto Iwase - Repository: naoto-iwase/Claude-R - Version: 20260209193839 - Stars: 0 - Forks: 0 - Last Updated: 2026-02-09 - Source: https://github.com/naoto-iwase/Claude-R - Web: https://mule.run/skillshub/@@naoto-iwase/Claude-R~claude-r:20260209193839 --- --- name: claude-r description: 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. --- # Claude-R - Execute R through RStudio Connect Claude Code to RStudio, enabling natural language R programming. RStudio acts as the execution engine; Claude generates and runs the code. ## Quick Start ### Prerequisites Check Verify RStudio server is running: ```bash uv run scripts/check_r_connection.py # or with system Python (if httpx installed) python scripts/check_r_connection.py ``` If not running: 1. Open RStudio 2. File -> Open Project -> select your .Rproj file 3. Run: `library(ClaudeR)` 4. Run: `claudeAddin()` 5. Click "Start Server" in Viewer pane ### Basic Usage Execute R code: ```r x <- 1:10 mean(x) ``` Generate plots: ```r 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 packages - `what: "variables"` - Workspace objects - `what: "version"` - R version - `what: "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 bash scripts/setup_clauder.sh ``` This installs: - R via Homebrew - System dependencies (harfbuzz, libtiff, libgit2, etc.) - R packages (renv, devtools, ClaudeR) ### Step 2: Choose Python Environment You'll need Python with `httpx` and `mcp` packages for the MCP server. **Option A: uv (Recommended)** No installation needed - dependencies loaded automatically: ```bash claude mcp add r-studio --scope user \ uv run --with httpx --with mcp python \ /path/to/ClaudeR/renv/library/.../ClaudeR/scripts/persistent_r_mcp.py ``` **Option B: System Python** Install dependencies first: ```bash python3 -m pip install --user httpx mcp claude mcp add r-studio --scope user \ python3 \ /path/to/ClaudeR/renv/library/.../ClaudeR/scripts/persistent_r_mcp.py ``` **Option C: Custom Python Environment** Use your preferred environment manager (venv, conda, etc.): ```bash # Example with venv python3 -m venv ~/.claude-r-env source ~/.claude-r-env/bin/activate pip install httpx mcp claude mcp add r-studio --scope user \ ~/.claude-r-env/bin/python \ /path/to/ClaudeR/renv/library/.../ClaudeR/scripts/persistent_r_mcp.py ``` ### Step 3: Start R Server 1. Open RStudio 2. File -> Open Project -> select your .Rproj file 3. `library(ClaudeR)` 4. `claudeAddin()` 5. Click "Start Server" ### Step 4: Verify Run `/mcp` in Claude Code - "r-studio" should show "connected" ## Architecture Three-layer system: 1. **Claude Code**: Natural language interface 2. **MCP Server**: Python bridge (stdio ↔ HTTP) 3. **ClaudeR HTTP Server**: R execution in RStudio (port 8787) RStudio acts passively - users interact with Claude Code, which generates and executes R code. RStudio's Environment, Plots, and Console panes show results. See [references/architecture.md](references/architecture.md) for details. ## Troubleshooting If R code execution fails, check connection: ```bash uv run scripts/check_r_connection.py ``` Common issues: - RStudio server not running - MCP configuration incorrect - Python dependencies missing See [references/troubleshooting.md](references/troubleshooting.md) for complete guide. ## Key Features - **State persistence**: R session persists across executions - **RStudio integration**: View variables, plots, and console in RStudio - **Natural language**: Generate 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](references/troubleshooting.md) - Connection issues, setup errors - [Architecture](references/architecture.md) - System design and data flow - [Setup Script](scripts/setup_clauder.sh) - Automated installation - [Connection Checker](scripts/check_r_connection.py) - Verify server status - [ClaudeR GitHub](https://github.com/IMNMV/ClaudeR) - Original project