Home

Use Claude Code for R in VS Code on Mac

You’ve set up R in VS Code and can write code manually. Now you want AI to help write, improve, and debug your R code while you focus on the analysis. Think of Claude Code as a coding partner who lives inside VS Code - you describe what you want, and it writes or improves the code while you stay in the same window.

Key Concepts

What You’ll Need

Step 1: Open VS Code and Create R Project

Step 2: Install and Sign in to Claude Code Extension

Step 3: Create Initial R Script Manually

data(iris)
str(iris)
summary(iris)

Step 4: Ask Claude to Add Scatter Plot

Add code to iris_analysis.R to create a scatter plot of sepal length vs. width, colored by species. Use ggplot2.

Step 5: Run the Updated Code

Step 6: Ask Claude to Refine Plot

Remove title. Change marker type by species. Change to the classic theme.

Step 7: Ask Claude for PCA Analysis

Add code to perform PCA on the numeric variables and plot the samples using the first two principal components.

Step 8: Ask Claude to Review and Comment

Review the entire script for correctness. Add comments when necessary.

Next Steps

Troubleshooting

Workflow Summary


Created by Steven Ge on December 11, 2025.