Plan for this week’s example

Cheatsheets

Click here to download the dplyr cheatsheet

tidyverse version

Note: If you are working locally, make sure you are running at least tidyverse 2.0.0:

# packageVersion("tidyverse")
# install.packages("tidyverse") # install updated version if < 2.0.0

Installing R packages

The functionality provided by a fresh install of R is only a small fraction of what is possible. In fact, we refer to what you get after your first install as base R. To access additional functionality, we can use add-ons made by developers. There are currently hundreds of these available from CRAN and many others shared via other repositories such as GitHub. However, because not everybody needs all available functionality, R instead makes different components available via packages. R makes it very easy to install packages from within R. For example, to install the tidyverse package, which we will use throughout the semester, you would just enter the following command in the R Console:

install.packages("tidyverse")

In RStudio, you can also do this by navigating to the Packages pane or via the Tools menu > Install Packages.

After installation is complete, we can then load the package into our current R session using the library function:

library(tidyverse)

You only need to install a package once if you are working with a local installation of R. On RStudio Cloud, you may sometimes need to install packages within multiple projects, but I will usually do this for you in advance. After that, you can load it using library whenever you need it. The package remains loaded until we quit the R session (or detach the package).

Note that installing tidyverse actually installs a large number of packages. This commonly occurs when a package has dependencies, or uses functions from other packages. When you load a package using library, you also load its dependencies.

You can see all the packages you have installed using the Packages tab in RStudio or via the following function:

installed.packages()

As we move through this course, we will learn more about packages and keep adding them to our toolbox.