How to install package or update package in R? – R tutorial

1504

R comes with a standard set of packages and includes base, datasets, utils, grDevices, graphics, stats, and methods. It provides a wide range of functions and datasets that are available by default. Other packages are available for download and installation. Once installed, they have to be loaded into the session in order to be used. The command search() tells you which packages are loaded and ready to use.

Installing Package in R

To install a package for the first time, use install. packages() command. Make sure you are connected to the internet.

Example, Installing Fincalc package

  1. Type install.packages("FinCal") and press the Enter/Return key. R will automatically download and install Fincalc package.
  2. To load the installed package. Just type library("FinCal") and press Enter/Return key.

Here comes a Trick: What if you want to install only if the package is not installed in your system?

Use the following command:

if(!require(FinCal)){install.packages("FinCal")}

This will install FinCal if it is not previously installed. Incase if it previously installed the above command will skip the download and load the package. Isn’t that handy?!

Updating package in R

You only need to install a package once. But like any software, packages are often updated by their authors. Use the command update.packages() to update any packages that you’ve installed.

For example: To update “FinCal” package use

update.packages("FinCal")

To know which version of R is installed Read: How to check the version of R language installed?

Previous articleWhat is Mean? How to Calculate the Mean Value?
Next articleVector Data Structure in R – R tutorial
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