You can expand R's capabilities by installing packages. It's common to get them from the CRAN package repository.
- Open an R session. (Use RStudio, base R, or whatever environment you use for R.)
- Place your cursor in the Console. (In RStudio, this is the lower left pane by default.)
- Type
install.packages("
package_name")
, e.g.:
install.packages("ggplot2")
- Press Enter to run the line.
- In some cases, you will see messages about download and installation. If you are prompted for a response, read the prompt and enter your response. When an empty new line (
>
followed by white space) appears in the Console, installation has finished.
Consider getting important package names from your instructors or from academic papers. You will need to know and type the name of your package precisely as it appears in CRAN.
You also can confirm whether a package is installed:
- Place your cursor in the Console.
- Type
"
package_name" %in% installed.packages()
, e.g.:
"ggplot2" %in% installed.packages()
- Press Enter to run the line.
- If the package is installed, you'll get the result
TRUE
. If not, you'll get the result FALSE
.