Packages in R Programming

Packages in detail

Packages in the R programming language are collections of R functions, compiled code, and sample data stored under a directory called “library” within the R environment. By default, R installs a set of basic packages during installation. When the R console starts, only these default packages are available. To use other installed packages, they need to be explicitly loaded.

What are Repositories?

A repository is a storage location for packages, enabling users to install R packages from it. Organizations and developers often have repositories, which are typically online and accessible to all. Some widely used repositories for R packages are:

CRAN: The Comprehensive R Archive Network (CRAN) is the official repository, consisting of a network of FTP and web servers maintained by the R community. Packages submitted to CRAN must pass rigorous testing to ensure compliance with CRAN policies.

Bioconductor: Bioconductor is a specialized repository for bioinformatics software. It has its own submission and review process and maintains high standards through active community involvement, including conferences and meetings.

GitHub: GitHub is a popular platform for open-source projects. Its appeal lies in unlimited space for open-source software, integration with Git (a version control system), and ease of collaboration and sharing.

Managing Library Paths

To get library locations containing R packages:

.libPaths()

Output:

[1] "C:/Users/YourUsername/AppData/Local/Programs/R/R-4.3.1/library"
Listing Installed Packages

To get a list of all installed R packages:

library()

Output:

Packages in library ‘C:/Users/YourUsername/AppData/Local/Programs/R/R-4.3.1/library’:

abind         Combine Multidimensional Arrays
ade4          Analysis of Ecological Data
askpass       Password Entry Utilities
base          The R Base Package
base64enc     Tools for Base64 Encoding
bit           Classes and Methods for Fast Memory-Efficient Boolean Selections
bit64         A S3 Class for Vectors of 64-Bit Integers
blob          A Simple S3 Class for Representing Vectors of Binary Data
boot          Bootstrap Functions
broom         Convert Statistical Objects into Tidy Data Frames
cachem        Cache R Objects with Automatic Pruning
callr         Call R from R
car           Companion to Applied Regression
caret         Classification and Regression Training
caTools       Tools: Moving Window Statistics, GIF, Base64, ROC AUC, etc
cli           Helpers for Developing Command Line Interfaces
colorspace    Color Space Manipulation
crayon        Colored Terminal Output
data.table    Extension of `data.frame`
DBI           Database Interface R
dplyr         A Grammar of Data Manipulation
ellipsis      Tools for Working with ...
forcats       Tools for Working with Categorical Variables
ggplot2       Create Elegant Data Visualizations
glue          String Interpolation
gridExtra     Miscellaneous Functions for "Grid" Graphics
gtable        Arrange 'Grobs' in Tables
lattice       Trellis Graphics
lubridate     Make Dealing with Dates a Little Easier
magrittr      A Forward-Pipe Operator for R
MASS          Support Functions and Datasets for Venables and Ripley's MASS
Matrix        Sparse and Dense Matrix Classes and Methods
methods       Formal Methods and Classes
pillar        Tools for Formatting Tabular Data
purrr         Functional Programming Tools
readr         Read Rectangular Data
readxl        Read Excel Files
scales        Scale Functions for Visualization
stats         The R Stats Package
stringr       Simple, Consistent Wrappers for Common String Operations
tibble        Simple Data Frames
tidyr         Tidy Messy Data
tidyverse     Easily Install and Load 'Tidyverse' Packages
tools         Tools for Package Development and Testing
utils         Utility Functions
xml2          Parse XML
xtable        Export Tables to LaTeX or HTML
yaml          Convert YAML to/from R
Installing R Packages

From CRAN: To install a package from CRAN

install.packages("dplyr")

To install multiple packages simultaneously:

install.packages(c("ggplot2", "tidyr"))

From Bioconductor: First, install the BiocManager package:

install.packages("BiocManager")

Then, install a package from Bioconductor:

BiocManager::install("edgeR")

From GitHub: Install the devtools package:

install.packages("devtools")

Then, use the install_github() function to install a package from GitHub:

devtools::install_github("rstudio/shiny")
Updating and Removing Packages

Update All Packages

update.packages()

Update a Specific Package

install.packages("ggplot2")

Check Installed Packages

installed.packages()
Loading Packages

To load a package:

library(dplyr)

Alternatively:

require(dplyr)
Difference Between a Package and a Library

People often confuse the terms “package” and “library,” and they are frequently used interchangeably.

  • Library: In programming, a library typically refers to the location or environment where packages are stored. For instance, the library() command is used to load a package in R and points to the folder on your computer where the package resides.
  • Package: A package is a collection of functions, datasets, and documentation conveniently bundled together. Packages are designed to help organize your work and make it easier to share with others.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *