install.packages("tidyverse")
install.packages("sf")
Preparing for the course
Installing Git and setting up a GitHub account
Set up two-factor authentication. This is highly recommended!
Installing R packages
Install the tidyverse and sf packages:
We will use these packages more than anything else.
Now, install {pak}
to get a better than basic installing packages:
install.packages("pak")
Here are all of the other packages we are using in this class.
::pkg_install(
pakc(
"mapview", "usethis", "quarto", "sf",
"tigris", "rnaturalearth", "spData", "arcgis"
) )
Configuring RStudio
Configuring RStudio is something we do together as a class during our first session. If you missed the first session, please review the instructions below to make sure your setup is the same as other members of the class
Required changes
Select Tools \> Global Options
from the menu then:
- Under the “Workspace heading”, uncheck the “Restore .RData” box.
- Under the same heading, “Save workspace to .RData on exit.” select “Never” from the drop-down.
- Select the Code panel, then check the box “Use native pipe operator, |> (requires R 4.1+)”
Optional changes
Select Tools \> Global Options
from the menu then:
- Select the “Pane Layout” options. I recommend placing the console in the top-right pane and the help and plot viewer in the bottom left. This is a personal preference and you can try a few options to see what works best for you.
- Select the “Appearance” options. This is the place you can customize the theme, code editor font, and code editor color scheme. Many programmers find a dark color scheme more readable. You may also want to try installing a “nerd font” or “programming” font. I use a font called FiraCode but you can find a wide variety of free fonts for download on this website.
Recommended Resources
- Review keyboard shortcuts.
Alternate IDEs
- Positron
Set up GitHub credentials in RStudio
If you are using RStudio instead of GitHub Desktop to update your repository, you also need to set up some local credentials so GitHub knows that RStudio is allowed to make changes to your personal or course repositories.
The {usethis}
documentation includes detailed article on connecting GitHub and R but it is more detail than you may need. These instructions are a brief summary of that article.
First, install the {usethis}
package (if you don’t have it installed already):
install.packages("usethis")
There are three steps to connect GitHub and RStudio:
Run
usethis::create_github_token()
to get a personal access token and copy the token to your clipboard. Make sure you are signed in to GitHub in your browser first! I also suggest setting the expiration to 90 days so you won’t need to refresh the token until after the end of this course.Run
gitcreds::gitcreds_set()
to put your PAT in your Git credential store.Restart your session and run
usethis::gh_token_help()
to double-check that the token is saved in the right place.
If you run into any trouble, you can run usethis::git_sitrep()
for more feedback on what is set up correctly and what (if anything) might need to be fixed.