Installing packages in R

108177

One of the main reason that R has become so popular is the vast collection of packages available at the CRAN repository. The base R system comes with basic functionality. The packages are developed and published by the larger R community. In the past few years, the availability of packages has grown exponentially from one thousands to ten thousands.

Command-line method to install packages in R

Installing packages using the command line is faster and easier process once you get used to it. Let’s see how to install a package named “quantmod“.

install.packages("quantmod")

Now we have learned how to install a single package in R. Next lets see how to install multiple packages. Use the following command to install a couple of packages namely quantmod and MASS.

install.packages(c("quantmod", "MASS"))

Graphical method to install packages in R

If you are looking to install R without entering commands then follow these steps in RStudio

Step 1: Go to Tools -> Install Package, and you will get a pop-up window.

Step 2: Type the package you want to install in the pop-up window.

Installing R packages from external repositories

The above methods will work for those packages that are available in CRAN i.e., Official repository of R. In certain cases you might be looking to install packages available in external repositories. For this first install a package devtools using the command, install.packages("devtools"). Once installed then you can use the following commands.

Installing R package from Bioconductor

install_bioc()

Installing R package from a git repository

install_git()

Installing R package from Bitbucket

install_bitbucket()

Installing R package from a URL

install_url()

Loading installed packages

Once you have installed packages. You have to load a package in R to make use of it. For this use the simple command

library(quantmod)
Previous articleIntroduction to R programming
Next articleLearn Data analysis in R
A.Sulthan, Ph.D.,
Author and Assistant Professor in Finance, Ardent fan of Arsenal FC. Always believe "The only good is knowledge and the only evil is ignorance - Socrates"
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments