Search This Blog

Packages in R

R packages are collections of functions and data sets developed by the community. They increase the power of R by improving existing base R functionalities, or by adding new ones. They are stored under a directory called "library" in the R environment. By default, R installs a set of packages during installation. More packages are added later when they are needed for some specific purpose. When we start the R console, only the default packages are available by default. Other packages which are already installed have to be loaded explicitly to be used by the R program that is going to use them. Basically, you can think of them as giving you SUPERPOWERS when you are doing your analysis. Because you can basically do anything with the packages that are available. Specifically, packages are bundles of codes that add new functions to R.

There are two general categories. The first one is Base packages which are installed with R but not loaded by default. The second category is Contributed Packages which need to be downloaded, installed, and loaded separately. These packages can be third-party packages.

I can hear you asking where to get these marvelous packages. There are three options

1.       CRAN

2.       Crantastic!

3.       GitHub

CRAN stands for Comprehensive R Archive Network is the official repository and it’s the most common source of packages. The R foundation coordinates it, and for a package to be published here, it needs to pass several tests that ensure the package is following CRAN policies.


The most commonly downloaded packages on R are packages like dplyr, tidyrii stringr, httr, ggvis, ggplot2, shiny, and rmarkdown. These packages make working with R much easier.

·         dplyr is the package that is used for data manipulation by providing different sets of verbs like select(), arrange(), filter(), summarise(), and mutate().

·         tidyr helps to create tidy data. A significant amount of work mostly goes on when cleaning and tidying the data. Basically, tidy data consists of those datasets where every cell acts as a single value, where every row is an observation, and every column is variable.

·       shiny can be used to build the web application without requiring JavaScript. It can be used together with htmlwidgets, JavaScript actions, and CSS themes to have extended features. Also, it can be used to build dashboards along with the standalone web applications.

·         ggplot2 is based on the 'Grammar of Graphics", which is a popular data visualization library. Graphs with one variable, two variables, and three variables, along with both categorical and numerical data, can be built. Also, grouping can be done through symbol, size, color, etc. The interactive graphics can be made with the help of plot.ly, where the 3D image should be made from plot3D.

How you can install a package will depend on where it is located. So, for publicly available packages, this means to what repository it belongs. The most common way is to use the CRAN repository, then you just need the name of the package and use the command install.packages("package").


To install more than one package at a time, just write them as a character vector in the first argument of the install.packages() function:


Uninstalling a package is also possible with the function remove.packages(), in your case:


Before a package can be used in the code, it must be loaded to the current R environment. You also need to load a package that is already installed previously but not available in the current environment.

A package is loaded using the following command

library(package Name)

Now you are good to go.

0 Comments:

Post a Comment