R Packages are collections of R functions, data, and compiled code in a well-defined format. The directory where packages are stored is called the library. R comes with a standard set of packages. Others are available for download and installation. Once installed, they have to be loaded into the session to be used.
R comes with standard (or base) packages, which contain the basic functions and data sets as well as standard statistical and graphical functions that allow R to work easily.
The packages are stored in three sources mainly –
The full form of CRAN is Comprehensive R Archive Network. It is an open source platform to store packages and other documents related to R. It is an open distributed platform , where anyone can store and download packages . It is default source to install packages in R.
It is a web based repository to store and collaboration features for development . We can store packages in this repository .
You can install package by following these steps :
1. Go to Package tab in right corner window . Choose Install option from the Package menu .
2. It will open Install Packages window .
3. Add package name under Packages(separate multiple with space or comma) . Add ggplot2 package to install.
4. I am installing package ggplot2 here . Click on Install button to install package.
5. It will show following output in Console window .
You can also install packages by using Script window. We can write this code to install “ggplot2” package.
To load “ggplot2” package we can write following code:
When we run this command , it will show this output .
We can also load “ggplot2” package by using another way :
We search ggplot2 in Package window . It will show this window.
For loading ggplot2 package , we tick mark ggplot2 . It will load ggplot2 package .
You can see output here :
If we unselect (un-tick) mark across ggplot2 , it will unload package from R .We can see the output here :
It shows following code in Console window :
It shows we detach package from R by above code or by just un-tick ggplot2 from package window.
You can also download multiple packages at the same time :
Install a package from Bioconductor :
First , we install Bioconductor package by :-
To install package “limma” from Bioconductor source :
Install a package from Github :
First install “devtools” package.
We are installing “survminer” package here :
In above code kassambara is User-name of github user . Survminer is package stored in github repository of kassambara(User ).
View loaded R packages :
To view the list of loaded (or attached) packages during an R session, use the function search():
Remove installed packages :
To remove an installed R package , we are using remove.packages() as follow:
It will remove “fpc” package from R.
Update installed packages :
If you want to update all R packages, type this:
To update specific installed packages “readr “and “ggplot2“, use this:
update.packages(oldPkgs = c(“readr”, “ggplot2”))