Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

packages
r
function
communitycreator

How to install a package in R

Onyejiaku Theophilus Chidalu

Overview

In R, a package is an extension that comprises data, codes, and documentation in a collection format, which can be installed by R users via a software repository such as Comprehensive R Archive Network (CRAN).

Some popular R packages are listed below:

  • tidyr
  • ggplot2
  • ggraph
  • dplyr
  • leaflet
  • ggmap
  • shiny
  • glue
  • plotly
  • caret

Installing an R package

To install a package in R, we use the install.packages() function. This function is used to install packages from repositories or local files.

Syntax

install.packages(pkgs)
Syntax for the install.packages() function

Parameter value

This function takes the parameter value, pkgs, which is a character vector having the name of any R packages that can be downloaded from the repositories.

Example

# implementing the install.packages() function 
install.packages("tidyr")
install.packages("ggplot2")
install.packages("ggraph")
Implementing the install.packages() function

Explanation

  • Line 2: We use the install.packages() function to install the "tidyr" package.
  • Line 3: We use the install.packages() function to install the "ggplot2" package.
  • Line 4: We use the install.packages() function to install the "ggraph" package.

      RELATED TAGS

      packages
      r
      function
      communitycreator

      CONTRIBUTOR

      Onyejiaku Theophilus Chidalu
      RELATED COURSES

      View all Courses

      Keep Exploring