R Packages Tutorial – Learn to Install & Use the Packages in R
1. R Packages
The objective of this R tutorial is to walk you through the packages in R. If you are new to R so follow our previous post on introduction to R programming. In this tutorial, we will discuss what is R packages, How to install R packages for Linux or Windows, How to use R Packages, next with the List of some useful Packages in R.
2. Packages in R
Before starting with packages in R, let us revise functions 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. You can see available packages by using the search() command.
Others are available for download and installation. Once installed, you need to load them into the session to use.
Below is an example of the running search() command:
>search()  “.GlobalEnv” “tools:RGUI” “package:stats” “package:graphics”  “package:grDevices” “package:utils” “package:datasets” “package:methods”  “Autoloads” “package:base”
When you use the search() command you can see what packages are being loaded and are ready for use. For example, you will see 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 can type the following command:
3. Installing R Packages for Windows
In Windows, you get the package menu and you get 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 internet(as .zip), you need to use Install Package(s) in packages menu. It allows you to select the files you need and again packages are being unzipped and installed into R.
4. Install R Packages for Linux
To install R packages on Linux system, you need to perform below steps:
- Download the required packages as compressed files from the following link:
- Run the following command to install packages:
R CMD INSTALL [options] [l-lib] pkgs
- Use the following command to load the installed package:
5. R Packages List
Below table specifies best R packages and 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|
6. R: Install Package for Linux
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:
7. Using Packages in R
We need to load the package in R after installing them to make them usable.
To load 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 on R Packages Tutorial. If you have any queries in R Tutorial, Please Comment.