Chapter 1: R Home
1. What exactly is “R Home” / R_HOME?
R_HOME is simply the folder (directory) where your R program itself is installed on your computer.
- It’s the root folder of the entire R installation.
- Everything important that belongs to R (not to your projects or packages you install later) lives inside or under this folder.
Think of it like:
- The “C:\Program Files\R\R-4.4.3” folder on Windows (example)
- or “/usr/lib/R” or “/opt/R/4.5.0/lib/R” on Linux
- or “/Library/Frameworks/R.framework/Versions/4.5/Resources” on macOS
This folder contains:
- The R executable itself
- All built-in functions & datasets
- Standard libraries that come with R
- Help files
- Configuration files (like Rprofile.site)
- Scripts that R runs automatically on startup
- etc.
2. Why do we even care about R_HOME?
Most beginners never need to think about it… until one day they do 😅
Common situations when R_HOME suddenly becomes important:
- You have multiple versions of R installed (very common!)
- You’re calling R from another program (Python with rpy2, Julia, .NET, Excel add-ins, JMP, etc.)
- You’re writing packages and need to find built-in files
- You’re troubleshooting weird installation problems
- You’re setting up system-wide configuration files
- You’re using Docker / conda / renv / packrat and need to know where base R lives
3. How to SEE what your R_HOME actually is (hands-on)
Open RStudio (or just plain R console) and type these one by one:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 |
# Most common & recommended way R.home() # Same thing — just different writing style R.home(component = "home") # Gives exactly the same result Sys.getenv("R_HOME") |
Typical outputs you’ll see (examples from real machines in 2026):
Windows
|
0 1 2 3 4 5 6 7 8 9 10 |
> R.home() [1] "C:/PROGRA~1/R/R-44~1.3" # or more readable version: > normalizePath(R.home()) [1] "C:/Program Files/R/R-4.4.3" |
macOS (Apple Silicon or Intel)
|
0 1 2 3 4 5 6 7 |
> R.home() [1] "/Library/Frameworks/R.framework/Resources" |
Linux / Ubuntu / server
|
0 1 2 3 4 5 6 7 8 9 |
> R.home() [1] "/usr/lib/R" # or sometimes [1] "/opt/R/4.5.0/lib/R" |
Try it now — what does yours say? Paste it in the next message if you want, and I can help interpret it.
4. Very useful sub-folders inside R_HOME
Once you know R_HOME, you can look at important sub-parts:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 |
# Where are the built-in datasets? file.path(R.home(), "library", "datasets") # Where is the help system? file.path(R.home(component = "doc"), "html") # Where are startup configuration files? file.path(R.home(), "etc") # ← very important folder! |
Inside R_HOME/etc/ you usually find:
- Rprofile.site → system-wide startup script (runs for everyone)
- Renviron.site → system-wide environment variables
- repositories → default CRAN mirrors, etc.
5. Quick comparison: R_HOME vs user HOME vs working directory
People often mix these up — let’s clarify with a table:
| Name | What it is | How to check in R | Typical example (Windows) | Typical example (Linux/macOS) |
|---|---|---|---|---|
| R_HOME | Where R program is installed | R.home() or Sys.getenv(“R_HOME”) | C:/Program Files/R/R-4.5.1 | /usr/lib/R or /opt/R/4.5 |
| User HOME | Your personal home folder | path.expand(“~”) or Sys.getenv(“HOME”) | C:/Users/webliance | /home/webliance or /Users/webliance |
| R_USER | R’s preferred user config location (Windows special) | Sys.getenv(“R_USER”) | often same as Documents or OneDrive/Documents | usually not set |
| Working dir | Current folder where files are read/saved | getwd() | whatever folder you set or project folder | same |
Very common confusion on Windows: R sometimes prefers Documents folder (or OneDrive/Documents) as “home” for user files (.Rprofile, .Renviron, history, etc.), not the real Windows user home.
You can check:
|
0 1 2 3 4 5 6 |
Sys.getenv(c("HOME", "R_USER", "R_HOME")) |
6. Small real-life example: Why someone might need R_HOME
Imagine you’re using Python + rpy2 and want to tell Python which R to use:
|
0 1 2 3 4 5 6 7 8 9 |
# in Python script import os os.environ["R_HOME"] = "C:\\Program Files\\R\\R-4.5.0" # ← exactly R_HOME path import rpy2.robjects as ro |
Or in a Docker container:
|
0 1 2 3 4 5 6 |
ENV R_HOME=/usr/local/lib/R |
Or if you want to read a file that ships with R:
|
0 1 2 3 4 5 6 7 8 |
# Read the famous iris dataset CSV version that comes with R iris_path <- file.path(R.home(), "library", "datasets", "iris.csv") read.csv(iris_path) |
7. Quick summary — cheat-sheet style
- R_HOME = installation folder of R itself
- Check it → R.home() or Sys.getenv(“R_HOME”)
- Most users never change it
- You usually only touch it when:
- multiple R versions
- calling R from another language
- advanced troubleshooting / deployment
Want to go deeper on any part?
- See what’s actually inside your R_HOME folder?
- Difference between R_HOME and user home on Windows?
- How multiple R versions work with RStudio?
- Or go back to data frames / dplyr examples?
Just say the word — I’m right here with the whiteboard ready! ☕📊
