Where Does R Store Packages and Startup Files?
R installs user packages to versioned library folders and reads .Rprofile plus .Renviron at startup. Paths on all platforms.
Last updated
R separates code, packages and config three ways. The system library lives under R_HOME, site libraries optionally beside it, and your packages in a versioned user library (R x.y in the path) that only counts when the folder exists. Startup then sources .Rprofile and .Renviron from the working directory first, home second.
Ask a live session instead of guessing: .libPaths() prints active trees, Sys.getenv('R_LIBS_USER') the default user one, normalizePath('~') the home R resolves. R 4.2 sets R_LIBS_USER even when empty, so interrogate rather than assume. Keep per-project .Rprofile files in version control and secrets in an untracked home .Renviron.
Where R stores this, by platform
%LOCALAPPDATA%\R\win-library\x.y
Versioned user library for R x.y.z. Home .Rprofile/.Renviron resolve under Documents via normalizePath('~'). R_LIBS and R_LIBS_USER override the search path.
~/Library/R/<arch>/<x.y>/library
CRAN-build user library with arch and version in the path. Same home-file startup order as elsewhere. Site libraries come from R_LIBS_SITE or R_HOME/site-library.
~/R/<platform>-library/<x.y>
Default user tree honoring R_LIBS_USER. R CMD check/build additionally read ~/.R/check.Renviron and build.Renviron. Startup package users gain Renviron.d and Rprofile.d layering.
Frequently asked questions
Where does R install my packages?
Into the first writable .libPaths() tree, usually the versioned user library above. Run .libPaths() to confirm. Set R_LIBS or R_LIBS_USER to redirect installs onto shared or bigger disks.
Which startup files does R read?
Renviron.site then user .Renviron for variables, Rprofile.site then user .Rprofile for code, each trying working directory before home. R_PROFILE, R_ENVIRON and the _USER variants override every default. Rscript skips some of these.
Notice an outdated path? Let us know.