library(MASS)
library(ISLR2)Libraries
Loading in Libraries
The library() function is used to load libraries, which are groups of functions and data sets not included in the base R distribution. Basic functions that perform least squares linear regression and other simple analyses come standard with the base distribution, but more exotic functions require additional libraries. Here, we load the MASS package, which is a very large collection of data sets and functions. We also load the ISLR2 package, which includes many of the data sets we’ll be working on in these textbook exercises.
Another common library used in R that isn’t necessarily for data analysis, but rather, data visualization, is ggplot2, which provides us with functions that provide greater control over the plots we create.
library(ggplot2)Error Messages
If you received an error message when loading any of these libraries, it likely indicates that the corresponding library has not yet been installed on your system.
Some libraries, such as MASS, come with R and do not need to be separately installed on your computer. However, other packages, such as ISLR2, must be downloaded the first time they are used. This can be done directly from within R.
Installing packages on Windows systems (Jupyter)
For example, on a Windows system, select the Install package option under the Packages tab. After you select any mirror site, a list of available packages will appear. Simply select the package you wish to install and R will automatically download the package.
Installing packages via the R command line
Alternatively, this can be done at the R command line via install.packages("ISLR2"). This installation only needs to be done the first time you use a package.

