How to install a R package?

To install an R package, you follow these steps:

  1. Launch RStudio or open an R console.
  2. Identify the name of the package you want to install. For example, let's say you want to install the "ggplot2" package for data visualization.
  3. In RStudio, you can either use the Packages tab in the lower right panel or directly type the following command in the R console:
R
install.packages("ggplot2")

This command tells R to download and install the "ggplot2" package from the Comprehensive R Archive Network (CRAN).

Press Enter or click the Run button to execute the command.

R will connect to the CRAN repository, download the package files, and install them on your system. The progress will be displayed in the console.


Once the installation is complete, you can load the package into your R session using the library() function. For example for "ggplot2" it will be like the following:


R
library(ggplot2)


The library() function loads the installed package, making its functions and capabilities available for use in your code.

That's it! You have successfully installed an R package. You can now utilize the functions and features provided by the package to enhance your data analysis, visualization, or any other task the package is designed for.