Installing R and RStudio

Getting Started with R

This guide covers the installation of R and RStudio, the essential tools for R programming.

What is R?

R is a free, open-source programming language for statistical computing and graphics.

What is RStudio?

RStudio is an integrated development environment (IDE) for R with syntax highlighting, code completion, and visualization tools.

Installation Guide

Installing R

Windows

  1. Go to the CRAN (Comprehensive R Archive Network) website
  2. Click on “Download R for Windows”
  3. Click on “base”
  4. Click on the download link for the latest version (e.g., “Download R-4.x.x for Windows”)
  5. Run the downloaded installer and follow the prompts
    • Accept default settings or customize as needed
    • Note installation location

macOS

  1. Go to the CRAN website
  2. Click on “Download R for macOS”
  3. Download the latest .pkg file for the system
  4. Open the downloaded file and follow installation instructions

Linux (Ubuntu/Debian)

  1. Open a terminal window

  2. Update your system’s package index:

    sudo apt update
  3. Install R:

    sudo apt install r-base

Installing RStudio

After installing R, install RStudio:

  1. Go to the RStudio download page
  2. Download the installer for the operating system
  3. Run the installer and follow prompts

Verification

To verify installation:

  1. Open RStudio

  2. In the Console, type:

    R.version
  3. Press Enter to display R installation information

Package Installation

Install packages using:

install.packages("packagename")

Example - tidyverse installation:

install.packages("tidyverse")

Essential Packages

Recommended packages for beginners:

install.packages("dplyr")      # Data manipulation and visualization
install.packages("rmarkdown")  # Dynamic documents
install.packages("knitr")      # Report generation
install.packages("shiny")      # Interactive web applications

Troubleshooting

Common Issues on Windows

  • Permission errors: Run RStudio as administrator
  • Path too long errors: Install R in a directory with a shorter path

Common Issues on macOS

  • Package installation failures: Install development tools:

    xcode-select --install

Common Issues on Linux

  • Missing dependencies: Install R dependencies:

    sudo apt install libcurl4-openssl-dev libssl-dev libxml2-dev