Useful R Packages
Packages are bundles of specialized code that you can add in to go beyond the basic R functions. When you install a package you are adding in extra coding options that can help you analyze or visualize your data more easily. Anyone can write packages and they can be general or very specific, so depending on your task, you may find someone has written a package to make it easier for you.
The terms "package" and "library" are used interchangeably. When using R you will run install.packages()
when you need to add a package for the first time, then you run library()
to load the package. install.packages()
is like buying a book—you only need to do it once—and library()
is like getting it off the shelf—you need to do it everytime you want to use that book.
The one package to rule them all
The first step in all of your scripts will likely be this line of code:
library(tidyverse)
{tidyverse} is a meta-package that will load many other packages within a single step. When you run the line above, it will load in the following packages for you automatically:
ggplot2
,dplyr
tidyr
readr
purrr
tibble
stringr
forcats
Below are categories that contain other useful packages. If you are trying to load in data from an online database (ex: US Census) be sure to check out the Direct Data Access libraries. There may be a library that will load your data in for you without the need for you to download it from the website.
Loading Data
Package Name |
What It Does |
Learn More |
readr | for loading in .csv, .txt, and more file types | readr documentation |
readxl | for loading .xlsx file types and other Excel extensions | readxl documentation |
haven | for loading Stata, SPS, and SPSS files | haven documentation |
jsonlite | for importing JSON objects and converting to R data types | jsonlite documentation |
googlesheets4 | for loading data from a Google Drive account | googlesheets4 documentation |
rvest | for web-scraping | rvest documentation |
duckdb | for loading more data than R likes to load; if you have a huge dataset, use this package | duckdb documentation |