8 Installing R Packages
We will be using specific R packages for the workshop, so you will need to install them. To make it easier, we’ve created a custom R package called r3 that will install all the necessary packages for you for this workshop. Run these two functions in the Console by copying and pasting them to install our custom r3 package as well as the tidyverse package.
Console
install.packages("r3", repos = c("https://rostools.r-universe.dev", "https://cloud.r-project.org"))
install.packages("tidyverse")Installing packages is tricky, especially on some work laptops, and doesn’t always work as expected. Here are some other methods to try if you have trouble installing the packages with the code above.
For Windows users, you may have to install RTools to use either the pak or remotes method. The version of RTools you install must match the version of R that you have installed. For example, if you have R version 4.4, you need to install RTools 4.4.
First, try installing the r3 package directly from GitHub with pak:
Console
install.packages("pak")
pak::pak("rostools/r3")If that doesn’t work, try with remotes:
Console
install.packages("remotes")
remotes::install_github("rostools/r3")If you encounter any errors with either of these functions, try to restart R by going to “Sessions -> Restart R” and re-run them again. If that also doesn’t work, try to complete the other tasks as best you can, complete the survey, and let us know you have a problem in the survey. We’ll email you at least a week before the workshop starts to try to help you get it working.
When you see a command like something::something(), for example with pak::pak(), you would “read” this as:
R, can you please use the
pak()function from the pak package.
The normal way of doing this would be to load the package with library(pak) and then running the command (pak()). But by using the ::, we tell R to directly use a function from a package, without needing to load the package and all of its other functions too. We use this trick because we only want to use the pak() command from the pak package and not have to load all the other functions as well. In this workshop we will be using :: often.