Packages in R Language

Packages in R Language store all the functions, datasets, and help files that significantly expand the language’s functionality beyond its core capabilities. When a package is loaded, its contents are available to work with. It makes the packages more efficient (as the full list takes more memory and time to search than a subset). The packages are also protected from name clashes with other codes.

Why Use R Packages?

  • Specialized Functionality: R packages offer tailored solutions for various domains, such as,
    • Biostatistics
    • Data mining
    • Machine learning
    • Financial analysis
    • Geospatial analysis
    • Text mining
  • Efficient Code and Algorithms: Many packages incorporate highly optimized C or C++ code, boosting performance and enabling complex computations.
  • Community-Driven Innovation: The R community actively develops and shares packages, ensuring a constant stream of new tools and techniques.
  • Standardized Data Formats: R Packages often include standard data formats, making it easier to work with diverse data sources.
  • Reproducibility: By using R packages, one can share his/her code and analyses more easily, making them reproducible for others

Seeing the Installed Packages

To see what packages are installed in your computer system, use the following command without arguments.

library()

To load particular packages in R (for example, mctest (https://CRAN.R-project.org/package=mctest) package containing functions to compute the multicollinearity diagnostics), use the command like:

library(mctest)
Packages in R Language

Installing and Updating Packages in R

One can install an R package if a system is connected to the internet using install.packages(). A package can also be updated by using the update.packages() command. (The installation of a package is also available through the Packages menu in the Windows and OS X GUIs.

# Installing a package
install.packages("mctest")

# Install Multiple Packages in R
install.packages(c("mctest", "lmridge", "liureg"))

# Updating a package
update.packages("mctest")

Currently Loaded Packages

One can see the packages that are currently loaded in the more by using the command

search()

Note that some packages may be loaded but not available on the search list, such packages may be seen by using

loadedNamespaces()
Packages in R

One can see a list of all available help topics in an installed package, by using the command

help.start()

An HTML help system will start. One can easily navigate to the package listing in the reference section.

Help System in R

Standard/ Base Packages in R

The base or standard packages are considered part of the R source code. The base packages contain the basic functions that allow R to work, and the datasets, standard statistical, and graphical functions that are described in this manual. These packages are automatically available in any R installation.

Contributed Packages and CRAN

There are thousands of contributed/ customized/ user-defined packages for R, written by many different authors. Some of these packages implement specialized statistical methods, some give access to data or hardware, and others are designed to complement textbooks. Most of the R packages are available for download from CRAN (https://CRAN.R-project.org/ and its mirrors).

Key R Package Repositories

  • CRAN: The primary repository for R packages, offering a vast array of options.
  • Bioconductor: Specializes in bioinformatics and computational biology tools.
  • GitHub: Hosts user-contributed packages and open-source projects.

Commonly Used Packages

  • Data Manipulation:
    • dplyr: For data manipulation and transformation.
    • tidyr: For tidying data.
  • Data Visualization:
    • ggplot2: For creating elegant and customizable plots.
    • plotly: For interactive visualizations.
  • Statistical Computing:
    • stats: The Base R package for statistical computations.
    • MASS: For more advanced statistical methods.
  • Machine Learning:
    • caret: For a unified interface to various machine learning algorithms.
    • randomForest: For random forest models.
    • xgboost: For gradient boosting machines.
  • Text Mining:
    • tidytext: For text mining and analysis.
  • Web Scraping:
    • rvest: For extracting data from websites.

Data Analysis and Statistics

Leave a Reply

Discover more from R Language Frequently Asked Questions

Subscribe now to keep reading and get access to the full archive.

Continue reading