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.

R Packages Tutorial - Learn to Install & Use the Packages in R

R Packages Tutorial – Learn to Install & Use the 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()
[1] “.GlobalEnv” “tools:RGUI” “package:stats” “package:graphics”
[5] “package:grDevices” “package:utils” “package:datasets”
“package:methods”
[9] “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:
installed.packages()

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:

http://cran.r-project.org/web/packages/available_packages_by_name.html

  • Run the following command to install packages:

R CMD INSTALL [options] [l-lib] pkgs

  • Use the following command to load the installed package:

library(package)

5. R Packages List

Below table specifies best R packages and their usage:

Package Name Use
ade4Used for analysis in ecological science
amapUsed for multidimensional analysis
ANNUsed for building and analyzing Artificial Neural Networks (ANN)
BayesLogitUsed for logistic regression analysis
C50Used for developing decision trees and rule-based models
latticeUsed for creating lattice graphics for panel plots or trellis graphs
MASSUsed for modern applied statics using S-PLUS
mgcvUsed for building generalized additive models

6. R: Install Package for Linux

The installation an of R packages (ade4) by using its name

The installation an of R packages (ade4) by using its name

In Linux, you can install the package if you know the name of a package.
Use the following command to install any package:
install.packages(‘ade4’)
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:

library(package)

In R, you can unload a package by using detach() command, as follows:

detach(package:name)

This was all on R Packages Tutorial. If you have any queries in R Tutorial, Please Comment.

See also-

Leave a Reply

Your email address will not be published. Required fields are marked *