How to Install a Package in R: A Complete Guide

R's real power comes from its ecosystem of packages — thousands of community-built libraries that extend the base language for everything from data visualization to statistical modeling. Knowing how to install them correctly is one of the first practical skills any R user needs.

What Is an R Package?

A package in R is a collection of functions, datasets, and documentation bundled together to solve specific problems. Base R ships with a core set of capabilities, but packages let you do far more — think ggplot2 for graphics, dplyr for data manipulation, or caret for machine learning.

Packages are hosted in several places:

  • CRAN (Comprehensive R Archive Network) — the official, curated repository with thousands of vetted packages
  • Bioconductor — a specialized repository for bioinformatics tools
  • GitHub — where developers publish experimental or in-development packages before a CRAN release

Where a package lives determines how you install it.

Installing a Package from CRAN

CRAN is the default source, and installing from it is straightforward. In your R console or RStudio: