ClaudeR |
![]() |
ClaudeR is an R package that creates a direct connection between RStudio and Claude AI, allowing for interactive coding sessions where Claude can execute code in your active RStudio session and see the results in real-time.
It can explore the data autonomously, or be a collaborator. The choice is yours.
This will also work with Cursor or any service that allows for MCP servers and can run RStudio.
Claude has the following MCP tools:
From these, you are able to do the following:
ClaudeR leverages the Model Context Protocol (MCP) to create a bidirectional connection between Claude AI and your RStudio environment.
MCP is an open protocol developed by Anthropic that allows Claude to safely interact with local tools and data sources.
In this case:
Check out the youtube video below for a quick example of what to expect when you use it
For security reasons, ClaudeR implements strict restrictions on code execution:
System commands: All system()
and system2()
calls are blocked, shell()
, and other methods of executing system commands.
File deletion: Operations that could delete files (like unlink()
, file.remove()
, or system commands containing rm
) are prohibited.
Error messages: When Claude attempts to run restricted code, the operation will be blocked and a specific error message will be returned explaining why.
These security measures exist to protect your system from unintended consequences when using an AI assistant:
Data Protection: While Claude is designed to be helpful, allowing unrestricted system access could potentially lead to accidental deletion or modification of important files.
Controlled Environment: By limiting operations to data analysis, visualization, and non-destructive R functions, we ensure Claude remains a safe tool for collaboration.
Principle of Least Privilege: Following security best practices, Claude is given only the permissions necessary to assist with data analysis tasks, not full system access.
Predictable Behavior: These restrictions create clear boundaries around what actions can be performed automatically versus what requires manual user intervention.
These restrictions only apply to code executed through the Claude integration. Normal R code you, the human, run directly is not affected by these limitations. If you need to perform restricted operations, you can do so directly in the R console. These restrictions are in place to protect you from any unexpected behavior. Claude is generally safe, but it's always better to be safe than sorry.
Prerequisites:
For Claude Desktop App use:
For Cursor:
Run this line inside your RStudio console. This command will download and install the ClaudeR package.
if (!require("devtools")) install.packages("devtools")
devtools::install_github("IMNMV/ClaudeR")
Now, run the setup function in your RStudio Console. This will install all needed R and Python libraries and automatically configure the config file.
For most users, the script will automatically find your system's Python. Simply run:
# First, load the package into your r session
library(ClaudeR)
# Now, run the installer for Claude Desktop:
install_clauder()
# Optional: If you are a Cursor user:
install_clauder(for_cursor = TRUE)
For Conda / Virtual Environment Users: If you need to use a specific Python from a Conda or virtual environment, you must provide the full path to that Python executable.
library(ClaudeR)
# Define the path to your specific Python
my_python_path <- "/path/to/your/conda/envs/my_env/bin/python"
# Run the installer with that path
install_clauder(python_path = my_python_path)
# Or
install_clauder(for_cursor = TRUE, python_path = my_python_path)
The script will guide you through the process. When it's finished, you must completely quit and restart the Claude Desktop and/or Cursor for the new settings to load.
After installation, launch the ClaudeR connection from your RStudio console
library(ClaudeR)
claudeAddin()
The ClaudeR add-in will appear in your RStudio Viewer pane.
In the addin interface:
Open Claude Desktop (or Cursor) and ask it to execute R code in your session
The ClaudeR addin provides several logging options:
Each R session gets its own log file with timestamps for all code executed. All code generated through chats will be saved to a single log file until the R session is restarted.
Once connected, you can ask Claude things like:
All in all, if you (a human) can do it with R, Claude can do it with R. Go nuts with it.
For Connection Issues:
For Python Dependency Issues:
"could not find function install_clauder" Error: If you see this after installing, restart your R session (Session -> Restart R
or Cmd/Ctrl + Shift + F10
) and try again. This ensures the newest version of the package is loaded.
Check that your Python environment is accessible
MCP Server Failed to Start in Claude/Cursor: This usually means the installer picked up a system Python that doesn't have the necessary libraries (mcp
, httpx
). Re-run the installer and provide a specific path to the correct Python environment, like a Conda or venv Python, using the python_path
argument.
install_clauder(python_path = "/path/to/your/conda/envs/my_env/bin/python")
Claude Can't See Results:
Warnings:
You may see a warning after installing dev tools, but it won't affect functionality. Bugs still exist, but I will work on fixing them as they arise.
If you stop the server then re-start it in the same R session, you may see the following:
"Listening on http://127.0.0.1:3071
createTcpServer: address already in use
Error starting HTTP server: Failed to create server"
This is a UI bug. The server is still active, and you can have Claude run code like normal. However, if you run into issues with Claude not being able to connect then the server you will need to switch the port to a different number in the Viewer Pane, or restart RStudio. If this issue causes Claude to not access the R environment please SAVE your work and click the 'Force Kill Server response' in the viewer pane. This will run the kill command on the backend:
kill -9 [PID]
This happens because the MCP server is made within the active R Studio session and thus that port is binded to it. So, by forcing this termination it will also terminate RStudio. It will only terminate the active RStudio window. Other active windows will not be affected. Switching the port number will also fix this issue.
MIT
Contributions are welcome! Please feel free to submit a Pull Request.
No configuration available
Related projects feature coming soon
Will recommend related projects based on sub-categories