R is an important programming language used heavily by statisticians. It is also used in machine learning, data science, research, and many more new fields. It is a computing environment where statistical data may be implemented. In this article, we shall discuss and learn about the packages in R.
Package in R
Packages are add-ons that can extend R's functionality and perform specific tasks covering a wide range of statistics. Packages are the collections of the R functions and data sets. The packages in R is developed by R Studio team as well as individuals.
There are several package (around 5k) available in R. Some of them are standard packages that come with R installation package, such as - tidyverse, shiny, ggplot2, readxl, devtools, plumber, gdata etc.
Installing Packages in R
We can install a package in R using
function install.packages() or following the steps of submenu Install Packages... which is the part of Tools menu. We can also install the packages manually after downloading from R Standard and official website site or from other sources available on Google.
Instailing Package By function install.packages()
To know more about
install.packages() function, you can type either
?install.packages() or
help(install.packages). It will show the documentation of
install.packages() in R Studio as shown in below images.
- ?install.packages()
- help(install.packages)
Now, suppose we want to install the package gdata, then we need to type the below command in R Studio.
- install.packages("gdata")
Now, it will show a window as shown in the below image. Basically, it shows the basic information about the package which you have given the command to install for. It shows the source from where it has been downloaded and it also gives the information about the size of the packages. After successful installation, it shows the directory where the packages have been installed.
Installing Package By R Studio Tools menu
To install packages in R Studio via Tools menu, click on Tools - Packages. It will show a window as shown below. Once you type the package name, it will automatically show the list of packages matching with your keyword. Here, you can provide multiple package names to be installed at a time. This will save your time. Keep in mind that we should install only a package that we need to use.
If you install a package that is already installed in R Studio, then it will give a warning as shown in the below images.
Using Package in R
So far, we have seen what packages are in R and how to install these. Now, we shall learn how to use a pacakge in R Studio.
To use a package in R, we use library() function as below.
-
- movies <- read.csv("Movie-Ratings.csv")
-
- install.packages("ggplot2")
-
- library(ggplot2)
- ggplot(data=movies, aes(x=CriticRating, y=AudienceRating))
-
- ggplot(data=movies, aes(x=CriticRating, y=AudienceRating)) +
- geom_point()