R keeps optional features in package libraries outside its base installation. CRAN provides released packages and their declared dependencies, while install.packages() handles repository lookup, download, and installation from an R session.
When the lib argument is omitted, R installs into the first directory returned by .libPaths(). Creating R's default personal library and putting it first for the current session avoids granting write access to the system library.
The withr example is a pure-R package that installs without a native-code compiler. Packages containing C, C++, or Fortran code can require platform build tools and system development libraries on Linux, while Windows and macOS often use a compatible CRAN binary when one is available.
$ R --quiet --no-save >
> package_lib <- Sys.getenv("R_LIBS_USER")
> dir.create(package_lib, recursive = TRUE, showWarnings = FALSE)
> .libPaths(c(package_lib, .libPaths()))
A later R session uses this directory automatically once it exists, provided the default R_LIBS_USER setting remains unchanged.
Related: Set a user package library in R
> install.packages("withr", repos = "https://cloud.r-project.org")
Installing package into '/home/analyst/R/aarch64-unknown-linux-gnu-library/4.5'
(as 'lib' is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/withr_3.0.3.tar.gz'
##### snipped #####
* DONE (withr)
The package name, archive type, and library path depend on the package, operating system, and R build. CRAN dependencies required for installation are fetched automatically.
Related: Fix an R package 00LOCK error
> find.package("withr")
[1] "/home/analyst/R/aarch64-unknown-linux-gnu-library/4.5/withr"
> withr::with_options(list(width = 40), getOption("width"))
[1] 40