b04-installing_packages_in_RStudio_AC01.Rmd
R is a programming language, and packages or libraries are bundles of software build using R. Most sessions using R involve using additional R packages.
NOTE: If you are working in an RStudio Cloud environment organized by someone else (eg a course instructor), they likely are taking care of many of the package management issues. The following information is still useful to be familiar with.
There is a point-and-click interface for installing R packages in RStudio. There is a brief introduction to downloading packages on this site: http://web.cs.ucla.edu/~gulzar/rstudio/
I’ve summarized it here:
The easiest way to install a package if you know its name is to use the function install.packages(). Note that it might be better to call this “download.packages” since after you install it, you also have to load it!
Frequently I will include install.packages(…) at the beginning of a lesson the first time we use a package to make sure the package is downloaded. Note, however, that if you already have downloaded the package, running install.packages(…) will download a new copy.
We’ll download a package used for plotting called ggplot2, which stands for “Grammar of Graphics.”
To download ggplot, run the following command:
Often when you download a package you’ll see a fair bit of red text, and sometime other things will pop up. Usually there’s nothing of interest here, but sometimes you need to read things carefully over it for hints about why something didn’t work.