R packages consists of a collection of R functions, data sets and compiled code which adds value to the existing R-functionalities. They are stored in the 'library' directory in the R-environment and developed by the community. For Example, "dplyr" is one of the commonly used packages in R which adds further functionalities with respect to working with dataframes.
There already exists some default packages in the local directory 'library' on your machine when you install R. We can see all the default packages by using code : 'library()'. If we want to add a new package, we can use three ways to do it:
This recipe demonstrates the installation and loading of a package from local machine using a .zip file. We can download a .zip file of a new package by acessing the following link: Visit R-Packages
Once the file has been downladed, we use the command " install.packages("file name along with its PATH", repos = NULL, type = 'source') " to install from the local machine. Below is the code for installation of "MASS" .zip file from the link above.
install.packages("MASS_7.3-53.zip",repos = NULL, type = 'source')
We use the function "library()" to load the package. It is essential to load the package before we can use it in your code.