0
0
R Programmingprogramming~5 mins

Package installation (install.packages) in R Programming

Choose your learning style9 modes available
Introduction

We use install.packages() to add new tools (packages) to R so we can do more things easily.

When you want to use a new feature or function not built into R by default.
When following a tutorial that requires a specific package.
When you need to analyze data with special methods provided by a package.
When you want to create graphs or reports using packages made for that.
When you want to update or add packages to your R setup.
Syntax
R Programming
install.packages("package_name")

Replace package_name with the name of the package you want to install, inside quotes.

You only need to install a package once on your computer.

Examples
This installs the ggplot2 package for making graphs.
R Programming
install.packages("ggplot2")
This installs the dplyr package for data manipulation.
R Programming
install.packages("dplyr")
This installs the tidyr package to help tidy data.
R Programming
install.packages("tidyr")
Sample Program

This program installs the stringr package, loads it, then changes text to uppercase and prints it.

R Programming
install.packages("stringr")
library(stringr)
text <- "Hello, R!"
result <- str_to_upper(text)
print(result)
OutputSuccess
Important Notes

You need an internet connection to download packages.

After installing, use library(package_name) to use the package in your session.

If you get an error, check spelling and your internet connection.

Summary

install.packages() adds new tools to R.

Use it once per package on your computer.

Load the package with library() before using it.