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