Installing Libraries

A simple guide for first-time R users on installing and loading essential libraries.

Installing Libraries

Libraries (or packages) are collections of R functions and data that extend R’s capabilities. In this guide, you’ll learn how to install and load some essential libraries to help you get started.


Installing Essential Libraries

To add new functionality to R, you first need to install the libraries. Run the following commands in your R console:

install.packages("devtools")    # Tools for package development
install.packages("tidyverse")     # A suite of packages for data manipulation and visualization
install.packages("lubridate")     # Simplifies working with dates and times
install.packages("readxl")        # Reads Excel files
install.packages("janitor")       # Cleans up data imports
install.packages("patchwork")     # Combines multiple plots
install.packages("skimr")         # Provides quick summary statistics
install.packages("plotly")        # Enhances ggplot2 with interactivity
install.packages("scales")        # Helps with ggplot2 axis scaling```

Load Libraries in scripts

After installation, load the libraries at the beginning of all of your R scripts using:

library(tidyverse) 
library(lubridate) 
library(scales) 
library(readxl) 
library(skimr) 
library(janitor) 
library(patchwork)

Optional: Useful Add-in Libraries

Some libraries add helpful tools to RStudio’s Addins menu (but not Positron), making it easier to reformat your code. Install these once and then load them as needed:

install.packages("ggThemeAssist")  # Assists with reformatting code

install.packages("styler")         # Automatically styles your code

And load them with:

library(ggThemeAssist)
library(styler)

In RStudio, you might need to enable the add-ins toolbar. Simply go to View > Show Toolbar to access them.

Addins_menu

Addins menu

These libraries are useful for general statistics and used quite often.

These are some of the better vetted statistical packages in my opinion for Anova and Linear Models

install.packages("car") # stats and ANOVA - essential 
install.packages("emmeans") # estimated marginal means for unbalanced designs 

# these only have to be installed and not run...
install.packages("multcomView") # paired comparisons - note this will interfear with DPLYR!!
install.packages("Rmisc") # stats 
install.packages("Hmisc") # stats install.packages("broom") # output models cleanly 

And load them with:

library(car)
library(emmeans)