R Packages

In this tutorial you will learn about the R Packages and its application with practical example.

R Packages

Package is simply a set of R functions organized in an independent, reusable unit. It usually contains set of functions for a specific purpose or utility along with the complied code and sample data. All of the R packages are stored in library directory. Every R package has its own context, thus it does not interfere with other modules.

R comes with a rich set of default packages, loaded automatically when R console is started. However, any other package other than the default need to be installed and loaded explicitly first in order to use it. Once a packages is loaded, it can be used throughout the R environment.

Check Package Directory Path

The .libPaths() function is used to show package directory path.

Example:-

Output:-

r_show_package_directory

List R Packages

The library() function is used to display list of all of the installed package.

Syntax:-

Output:-

The search() function is used to display list of all of the packages currently loaded in the R environment.

Syntax:-

Output:-

Installing R Package

In R, there are two ways we can install a new package.

Install using CRAN:-

CRAN is a distributed network around the world that store identical, up-to-date versions of a package code and documentation, which allows you to install a packages from nearest CRAN mirror.Use the following commands to install a R package directly from CRAN mirror –

Install Manually:-

Step 1:- Download the R Package directly from the following link –

Step 2:- Save package zip file in your local system.

Step 3:- Install the package using following commands

Load Package

In R, all of the default packages are loaded automatically when R console is started. However, any other package other than the default need to be installed and loaded explicitly first in order to use it. Once a packages is loaded, it can be used throughout the R environment. In R, a package can be loaded using following commands –

Updating Package

Once a package is installed, you may frequently require to update them in order to have an latest package code. A package can be updated using update.packages command as following –

Delete Package

Sometime you may require to delete any package, this can be done using the remove.packages() function as following –

In this tutorial we have learn about the R Packages and its application with practical example. I hope you will like this tutorial.