Skip to content

Commit 0f330d3

Browse files
tdhopperclaude
andcommitted
Add R package setup script for separate R installation
Create setup_r.sh to install required R packages (ggplot2, mgcv) without requiring conda. Works with system R installations via Homebrew, apt, or CRAN. This allows using uv for Python dependencies while maintaining R integration through rpy2 with a separate R installation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c69894b commit 0f330d3

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

setup_r.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
3+
# Setup script for R and required R packages
4+
# This script installs the R packages needed for pythonplot.com
5+
6+
set -e # Exit on error
7+
8+
echo "Installing R packages..."
9+
10+
# Check if R is installed
11+
if ! command -v R &> /dev/null; then
12+
echo "Error: R is not installed."
13+
echo ""
14+
echo "Please install R first:"
15+
echo " - macOS: brew install r"
16+
echo " - Ubuntu/Debian: sudo apt-get install r-base r-base-dev"
17+
echo " - Or download from: https://cran.r-project.org/"
18+
exit 1
19+
fi
20+
21+
echo "R version:"
22+
R --version | head -n 1
23+
24+
# Install required R packages
25+
R --quiet --no-save << 'EOF'
26+
# Set CRAN mirror
27+
options(repos = c(CRAN = "https://cran.rstudio.com/"))
28+
29+
# List of required packages
30+
packages <- c("ggplot2", "mgcv")
31+
32+
# Install packages that aren't already installed
33+
for (pkg in packages) {
34+
if (!require(pkg, character.only = TRUE, quietly = TRUE)) {
35+
cat(paste("Installing", pkg, "...\n"))
36+
install.packages(pkg, quiet = FALSE)
37+
} else {
38+
cat(paste(pkg, "is already installed\n"))
39+
}
40+
}
41+
42+
# Verify installations
43+
cat("\nVerifying R package installations:\n")
44+
for (pkg in packages) {
45+
if (require(pkg, character.only = TRUE, quietly = TRUE)) {
46+
cat(paste("✓", pkg, "version", as.character(packageVersion(pkg)), "\n"))
47+
} else {
48+
cat(paste("✗", pkg, "FAILED TO INSTALL\n"))
49+
quit(status = 1)
50+
}
51+
}
52+
53+
cat("\n✓ All R packages installed successfully!\n")
54+
EOF
55+
56+
echo ""
57+
echo "R setup complete!"
58+
echo ""
59+
echo "Note: If you encounter issues with rpy2, make sure R_HOME is set correctly:"
60+
echo " export R_HOME=\$(R RHOME)"

0 commit comments

Comments
 (0)