R Packages Tutorial – How to Install & Use Packages in R Programming
In this tutorial, we will explore the concept of packages in R programming along with its installation process in Windows and Linux. Also, we will learn about different R packages with their specific use and process to load packages in R.
Wait! Have you checked the tutorial on R Arguments
Stay updated with latest technology trends
Join DataFlair on Telegram!!
Packages in R
A package is a collection of R functions, data, and compiled code in a well-defined format. Packages are being stored in the directory called the library. R comes with a standard set of packages. With the help of the search() command, you can find all the list of available packages that are installed in your system.
Others are available for download and installation. Once installed, you need to load them into the session to use.
We can observe an example of search() command as follows:
When the search() command is executed, you can overview the packages that are loaded and are ready for use. You will see the graphics package that carries out routines to create graphs.
There are many packages that are being installed but not loaded by themselves. For example – Splines package, that contains routines for smoothing curves, is being installed. But this splines package is not loaded by itself.
To see what packages are available, you need to type the following command:
Time to gain expertise in R Graphical Models
How to Install R Packages for Windows
In Windows, you get the package menu and install option which is very easy.
After selecting a local mirror site, a list of available binary packages is being shown. You can choose the ones you need. Once you have selected the packages you need, you need to click the OK button to download and install them into R.
If you download the package files from the internet(as .zip), you need to use the install package(s) in the packages menu. It allows you to select the files you need and again packages are unzipped and installed into R.
How to Install R Packages for Linux
To install R packages on the Linux system, you need to perform the below steps:
- Download the required packages as compressed files from the link: Available packages by name
- Run the following command to install packages:
R CMD INSTALL [options] [l-lib] pkgs
- Use the following command to load the installed package:
Don’t forget to check the Matrix Function in R
Installing by the Name of Package
In Linux, you can install the package if you know the name of a package.
Use the following command to install any package:
The following figure shows the installation of an ade4 package by using its name:
R Packages List
The below table specifies the best packages in R with their usage:
|ade4||Used for analysis in ecological science|
|amap||Used for multidimensional analysis|
|ANN||Used for building and analyzing Artificial Neural Networks (ANN)|
|BayesLogit||Used for logistic regression analysis|
|C50||Used for developing decision trees and rule-based models|
|lattice||Used for creating lattice graphics for panel plots or trellis graphs|
|MASS||Used for modern applied statics using S-PLUS|
|mgcv||Used for building generalized additive models|
The concept that you can’t miss – R Lattice Package
How to Use Packages in R
We need to load the package in R after installing them to make them usable.
To load the R language Package, you can use the library() command, as follows:
In R, you can unload a package by using detach() command, as follows:
This was all in R Packages tutorial. Hope you liked our explanation.
The next step in your R programming journey – R Statistical Programming
Any queries related to the article? Share your views in the comment section below.