R packages are the collection of R functions, sample data, and compile codes. In the R environment, these packages are stored under a directory called “library.” During installation, R installs a set of packages. We can add packages later when they are needed for some specific purpose. Only the default packages will be available when we start the R console. Other packages which are already installed will be loaded explicitly to be used by the R program.
There is the following list of commands to be used to check, verify, and use the R packages.
Check Available R Packages
To check the available R Packages, we have to find the library location in which R packages are contained. R provides libPaths() function to find the library locations.
When the above code executes, it produces the following project, which may vary depending on the local settings of our PCs & Laptops.
 "C:/Users/ajeet/OneDrive/Documents/R/win-library/3.6"  "C:/Program Files/R/R-3.6.1/library"
Getting the list of all the packages installed
R provides library() function, which allows us to get the list of all the installed packages.
When we execute the above function, it produces the following result, which may vary depending on the local settings of our PCs or laptops.
Packages in library ‘C:/Program Files/R/R-3.6.1/library’:
Like library() function, R provides search() function to get all packages currently loaded in the R environment.
When we execute the above code, it will produce the following result, which may vary depending on the local settings of our PCs and laptops:
 ".GlobalEnv" "package:stats" "package:graphics"  "package:grDevices" "package:utils" "package:datasets"  "package:methods" "Autoloads" "package:base"
Install a New Package
In R, there are two techniques to add new R packages. The first technique is installing package directly from the CRAN directory, and the second one is to install it manually after downloading the package to our local system.
Install directly from CRAN
The following command is used to get the packages directly from CRAN webpage and install the package in the R environment. We may be prompted to choose the nearest mirror. Choose the one appropriate to our location.
The syntax of installing XML package is as follows:
Install package manually
To install a package manually, we first have to download it from https://cran.r-project.org/web/packages/available_packages_by_name.html. The required package will be saved as a .zip file in a suitable location in the local system.
Once the downloading has finished, we will use the following command:
Install the package named “XML”
Load Package to Library
We cannot use the package in our code until it will not be loaded into the current R environment. We also need to load a package which is already installed previously but not available in the current environment.
There is the following command to load a package:
Command to load the XML package