R Packages

R provides a good collection of functions for solving many developmental problems. These collections are called packages. Some packages are installed by default with R installation. Most of the packages are available on R official website http://CRAN.R-project.org/ , that we can easily install later as per our requirement .

Get list of all installed packages

The library() function displays all the installed packages in your system.

library()

The above command displays the following results and this may vary depending on the settings of your pc.

Packages in library 'C:/Program Files/R/R-3.5.1/library':
base                    The R Base Package
boot                    Bootstrap Functions (Originally by Angelo Canty
                        for S)
class                   Functions for Classification
cluster                 "Finding Groups in Data": Cluster Analysis
                        Extended Rousseeuw et al.
codetools               Code Analysis Tools for R
compiler                The R Compiler Package
datasets                The R Datasets Package
foreign                 Read Data Stored by 'Minitab', 'S', 'SAS',
                        'SPSS', 'Stata', 'Systat', 'Weka', 'dBase', ...
graphics                The R Graphics Package
grDevices               The R Graphics Devices and Support for Colours
                        and Fonts
grid                    The Grid Graphics Package
jsonlite                A Robust, High Performance JSON Parser and
                        Generator for R
KernSmooth              Functions for Kernel Smoothing Supporting Wand
                        & Jones (1995)
lattice                 Trellis Graphics for R
MASS                    Support Functions and Datasets for Venables and
                        Ripleys MASS
Matrix                  Sparse and Dense Matrix Classes and Methods
methods                 Formal Methods and Classes
mgcv                    Mixed GAM Computation Vehicle with Automatic
                        Smoothness Estimation
mime                    Map Filenames to MIME Types
mongolite               Fast and Simple 'MongoDB' Client for R
nlme                    Linear and Nonlinear Mixed Effects Models
nnet                    Feed-Forward Neural Networks and Multinomial
                        Log-Linear Models
openssl                 Toolkit for Encryption, Signatures and
                        Certificates Based on OpenSSL
parallel                Support for Parallel computation in R
rJava                   Low-Level R to Java Interface
rpart                   Recursive Partitioning and Regression Trees
spatial                 Functions for Kriging and Point Pattern
                        Analysis
splines                 Regression Spline Functions and Classes
stats                   The R Stats Package
stats4                  Statistical Functions using S4 Classes
survival                Survival Analysis
tcltk                   Tcl/Tk Interface
tools                   Tools for Package Development
translations            The R Translations Package
utils                   The R Utils Package
xlsx                    Read, Write, Format Excel 2007 and Excel
                        97/2000/XP/2003 Files
xlsxjars                Package required POI jars for the xlsx package
XML                     Tools for Parsing and Generating XML Within R
                        and S-Plus




Load an installed package

The library() function is also used while loading an installed package.

library(package_name)

Get Library Path

R provides libPaths() function to know the library paths in your system.

.libPaths()

Change Library Path

If you want to change the library path, first makes it blank and then assign the desirable path in it. Suppose, we want to make the library installation path to 'C:/Program Files/R/R-3.5.1/library'.

.libPaths('')
.libPaths('C:/Program Files/R/R-3.5.1/library')

Install a package from CRAN

To install a package from CRAN web page, follows the following syntax.

install.packages("package_name")

At the time of package installation, make sure to open R prompt as Administrator. So that you have right privileges to install the package.


Install a downloaded package

To install a downloaded package, follows the following syntax.

install.packages("full source path", repos = NULL, type = "source")





Uninstall a package

To uninstall a package, follows the following syntax.

remove.packages(pkg, lib)

Here, pkg is the name of the package to remove and lib is the library directory to remove.

Example

remove.packages('rJava', 'C:/Program Files/R/R-3.5.1/library')







Read more articles


General Knowledge



Learn Popular Language