How to install a package in R

How to install a package in R


  R Interview Questions

Packages is where the power of R lies. R has close to 10,000 packages available at CRAN. There is a package for just about anything in R. It is very easy to install packages in R.

Install a packages

Installing a package in R is simple. For example, the following statement installs the “plotly” package.

> install.packages("plotly")

Install multiple packages in one go

<strong>> install.packages( c("plotly","ggplot2") )</strong>

Install packages in R Studio

R studio makes life easy by providing a GUI for this.

you can specify multiple packages as well.

Where are these packages installed ?

These packages are installed in the library path which you can find out through

> .libPaths()
[1] "C:/Users/AjayTech/Documents/R/win-library/3.4"
[2] "C:/Program Files/R/R-3.4.3/library"

How can you load packages ?

Installing a library is one thing, but you have to load them to be usable by your programs. You load them as below.

# Note that there is no quotes this time. 
> library(ggplot2)

How can you remove a package in R ?

It is as easy as installing a package

> remove.packages( c("ggplot2","plotly"))
Removing packages from 'C:/Users/AjayTech/Documents/R/win-library/3.4'
(as 'lib' is unspecified)

Or using the R Studio GUI.

How to get help on a particular R package

> help(package="caret")

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: