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&gt;&gt; install.packages( c("plotly","ggplot2") )</strong&gt;

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

&gt; .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. 
&gt; library(ggplot2)

How can you remove a package in R ?

It is as easy as installing a package

&gt; 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

&gt; help(package="caret")

Leave a Reply

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