Skip to content

R

Installing R

You can install R directly from the Comprehensive R Archive Network (CRAN) by following the instructions on the CRAN website. Alternatively, you can use a version management tool like rig to manage multiple R versions easily.

Install R from CRAN (best for beginners)

  • Download and install R from the CRAN website by following the instructions for your operating system.
  • R will be installed system-wide, and you can start using it immediately.

Install R using rig (for advanced users)

rig allows you to install and manage multiple R versions.
You can install rig using Homebrew on macOS or Linux:

sh
brew tap r-lib/rig
brew install --cask rig

You can use Scoop on Windows:

sh
scoop bucket add r-bucket https://github.com/cderv/r-bucket.git
scoop install rig

After installing rig, you can install the latest version of R using rig:

sh
rig install release

To install the latest development version of R, use:

sh
rig install devel

You can switch between installed R versions using:

sh
rig default <version>

Installing R packages

You can install R packages using:

  • the install.packages() function in base (recommended for beginners)
  • the pak package (recommended for advanced users)

Install packages using install.packages() (best for beginners)

To install R packages using the base R function install.packages(), you can run the following command in your R console:

R
install.packages("package_name")

Install packages using pak (for advanced users)

The pak package provides a fast and reliable way to install R packages and their dependencies. To use pak, first install it using install.packages():

R
install.packages("pak")

Then, you can install packages using pak::pak():

R
pak::pak("package_name")

Project environments with renv (for advanced users)

In R, you usually don't have to install dependencies for each project separately. Version conflicts are rare and maintaining a global package library is the default and recommended way of working with R. This avoids unnecessary duplication of packages on your disk.

If you do want or need to create a new R project, you can create a project-specific environment using renv.

Resources

Programming for Data Science in R (PDSR)