Chapter 2 Accessing Packages

R is a power programming language for data and statistical analysis. The language has many excellent functionalities that allow for various data and statistical analysis. R can be extended by adding features outside the base functionality, which is done by adding packages. A package is a collection of functionality made available within a single installation. R has a great community with many individuals and organizations who develop and publish packages free of charge. Within this section will explore how to install and load packages within the RStudio environment.

2.1 Installing Packages

Packages can be installed within RStudio in either a code block or within the console section of RStudio.

2.1.1 Install a Single Package

Description
Method to install a single package in R
Ingredients
Package Data
NA NA


Sample Instructions

install.packages("package_name")


Actual Instructions

install.packages("readr")

2.1.2 Install Multiple Packages

Description
Method to install multiple packages in R
Ingredients
Package Data
NA NA


Sample Instructions

install.packages(c("package_name1","package_name2", "package_name3"))


Actual Instructions

install.packages(c("readr", "dplyr", "tidyr"))

2.2 Loading Packages

Once a package has been installed into RStudio it must be loaded into the RStudio environment. Each time you write code (i.e. a RNotebook, RMarkdown document, script, etc.) the specific packages that will be used must be loaded. The most common method for loading packages is to place the commands within a code block section.

2.2.1 Load a Single Package

Description
Method to load and gain access to the functionality of a package in R
Ingredients
Package Data
NA NA


Sample Instructions

library(package_name)


Actual Instructions

library(readr)

2.2.2 Load Multiple Packages

Description
Method to load and gain access to the functionality of multiple packages in R
Ingredients
Package Data
NA NA


Sample Instructions

library(package_name1)
library(package_name2)
library(package_name3)


Actual Instructions

library(readr)
library(dplyr)
library(tidyr)