Tutorial: R and RStudio setup
This is a short, practical guide for new lab members setting up R and RStudio on their own laptop (MacBook first).
Official references:
- CRAN macOS R installers: https://cran.r-project.org/bin/macosx/
- RStudio Desktop download: https://posit.co/download/rstudio-desktop/
1) Check your Mac architecture
uname -m
arm64→ Apple Silicon (M1/M2/M3/M4 and newer)x86_64→ Intel Mac
2) Install R (from CRAN)
- Open CRAN macOS page: https://cran.r-project.org/bin/macosx/
- Download the correct installer for your architecture:
- Apple Silicon:
R-*-arm64.pkg - Intel:
R-*-x86_64.pkg
- Apple Silicon:
- Run the
.pkginstaller and finish setup.
Verify in Terminal:
R --version
3) Install RStudio Desktop
- Download from Posit: https://posit.co/download/rstudio-desktop/
- Install RStudio Desktop.
- Launch RStudio and confirm it detects your R installation.
4) First-time setup in RStudio
Open RStudio Console and run:
install.packages(c("tidyverse", "data.table", "remotes"))
Set a CRAN mirror when prompted.
5) Create a project (recommended workflow)
In RStudio:
- File → New Project
- choose a dedicated folder per project
- keep scripts/data/results together
This helps reproducibility and collaboration.
6) Optional: project-local package management with renv
Inside a project, run:
install.packages("renv")
renv::init()
After installing/updating packages:
renv::snapshot()
A collaborator can restore the same package set with:
renv::restore()
7) Common issues
- RStudio says “R not found”:
- install/reinstall R from CRAN first, then restart RStudio.
- Package install fails on macOS:
- update to current R version first,
- then retry package install.
- Apple Silicon users with old Intel-only package binaries:
- update R and packages; avoid mixing very old package builds.
8) Lab recommendation
Use one RStudio Project per study and use renv for reproducibility before sharing analysis code.