Skip to content

R - Environment Setup

Setting up a modern R development environment involves two key components:

  1. R: The programming language and core compiler itself.
  2. RStudio Desktop: A powerful and free Integrated Development Environment (IDE) that makes working with R much more efficient. It includes a code editor, an R console, plotting windows, package management tools, and much more.

The recommended setup process is to first install R, and then install RStudio.

Always download R from the official Comprehensive R Archive Network (CRAN). This ensures you are getting the latest stable version.

  1. Go to the CRAN website for Windows.
  2. Click the prominent link to “Download R-X.X.X for Windows” (where X.X.X is the latest version number).
  3. Run the downloaded .exe installer. It is safe to accept the default settings during installation.
  1. Go to the CRAN website for macOS.
  2. Choose the appropriate package (.pkg file) for your version of macOS and your Mac’s processor (Apple Silicon M1/M2 or Intel).
  3. Open the downloaded .pkg file and follow the installer instructions.
  4. Alternative (for command-line users): If you use Homebrew, you can install R by running brew install r in your terminal.

You can install R using your distribution’s package manager. Open a terminal and run the appropriate command:

# For Debian/Ubuntu
sudo apt update
sudo apt install r-base
# For Fedora/RHEL/CentOS
sudo dnf install R

For more detailed instructions, refer to the CRAN Linux documentation.

Once R is installed, download and install RStudio.

  1. Go to the RStudio Desktop download page.
  2. The website should automatically recommend the correct installer for your operating system. Download it.
  3. Run the installer, accepting the default settings.

After installation, you can launch RStudio. You will see an integrated environment with a console pane, which is where you can type R commands. You will write your code in the script editor (top-left pane).

One of R’s greatest strengths is its vast collection of third-party packages. You can install packages from CRAN using the install.packages() function. For example, to install the ggplot2 package for advanced data visualization:

> install.packages("ggplot2")

A highly recommended starting point for any new R user is to install the tidyverse, which is a collection of essential data science packages that share a common design philosophy, including ggplot2 (for plotting), dplyr (for data manipulation), readr (for reading data), and more.

# This single command installs a suite of powerful, modern R packages
> install.packages("tidyverse")
# To use a package in your R session, you must load it with the library() function
> library(tidyverse)