Getting Started with R, RStudio, and GitHub for DS421
📦 Step 1: Install / Update R
- Visit the official R website: https://cran.r-project.org
- Click Download R for (your OS) — choose Windows, macOS, or Linux
- Follow the installer instructions
✅ Confirm installation by opening R and typing
version
🧰 Step 2: Install / Update RStudio
- Go to https://posit.co/download/rstudio-desktop/
- Download the free version of RStudio Desktop
- Install and open RStudio
✅ RStudio should automatically detect your R installation
🐙 Step 3: Create / Update your GitHub Account
- Navigate to https://github.com
- Sign up using your school or personal email
- Choose a username you’ll use professionally (e.g.,
csmith-ds421
) - Verify your email and log in
✅ Tip: Add a profile picture and short bio (e.g., “Cartographic Design student”)
📁 Step 4: Create a Repository for Class
- On GitHub, click the + icon > New repository
- Name it:
DS421-Carto-Design
- Add a short description: “Projects for Cartographic Design (DS421)”
- Set visibility to Public or Private (your choice)
- ✅ Check the box to add a
README.md
- Click Create repository
📎 Your repo URL will look like:
https://github.com/yourusername/DS421-Carto-Design
🔗 Step 5: Check for / Install Git & Link GitHub to RStudio
Check for Git
For macOS users
Open RStudio and use the Terminal tab (bottom left panel). Type:
which git
If you see something like /usr/bin/git
, you’re good! If not, install Xcode Command Line Tools.
For Windows users
In the Terminal tab in RStudio, type:
where git
If no result is shown, download Git for Windows: https://git-scm.com/download/win
Configure Git
Run the following in the RStudio Terminal (replace with your GitHub name/email):
git config --global user.name "Jane Doe"
git config --global user.email janedoe@example.com"
Check your setup:
git config --list --global
Generate and Store a GitHub PAT
A PAT (Personal Access Token) is needed to push to GitHub securely.
- In the Console tab (next to Terminal):
install.packages("usethis")
::create_github_token() usethis
This opens a GitHub page. Name the token (e.g.
ds421-laptop
) and click Generate token.Copy the token to your clipboard (you won’t be able to see it again).
Back in the Console:
::gitcreds_set() gitcreds
Paste your token when prompted.
Check that everything works:
::git_sitrep() usethis
✅ You should see your GitHub username and confirmation that credentials are set.
🧮 Step 6: Create a New RStudio Project Linked to GitHub
- Open RStudio
- Go to File > New Project
- Choose Version Control > Git
- Paste your GitHub repo URL (e.g.,
https://github.com/yourusername/DS421-Carto-Design
) - Choose a local folder on your computer to store the project
- Click Create Project
🧠 You’ve now cloned your repo and linked it to RStudio.
You should now see the README.md
file in your RStudio Files pane.
🗺️ Step 7: Install mapgl
and Set Up Mapbox Token
The mapgl
package allows you to create beautiful interactive maps using Mapbox. To use it, you’ll need a Mapbox access token.
Install mapgl
install.packages("mapgl")
Set up Mapbox Access Token
💡 Please do not put any credit card info
Store Your Token in R
In the Console:
::edit_r_environ() usethis
This opens your .Renviron
file. Add the line:
MAPBOX_PUBLIC_TOKEN='pk.eyJ1IjoiY29ubm9yZmx5bm4iLCJhIjoiY2x5cWFtZzk0MGU4MzJqb2F0a2w1bGJkZiJ9.fB81ysj5JOrG16upKvzk4A'
Save and restart RStudio. The mapgl()
function will now automatically detect your token.
📘 More info: Getting Started with mapgl
🔄 Step 8: Make a Test Commit
- Create a new R script: File > New File > R Script
- Add the following code to test your
mapgl
installation:
library(mapgl)
mapboxgl()
- Save the script as
mapgl_intro.R
- Run the script — a globe should appear in the Viewer pane like this:
- In the Git tab (top-right pane), check the boxes next to the new files
- Click Commit, write a short message like
Initial mapgl test
, and click Commit - Click Push to upload your changes to GitHub
🧪 Check your GitHub repo — your script should be visible online.
🧭 You’re All Set!
You now have: - ✅ R and RStudio installed - ✅ Git and GitHub connected to RStudio - ✅ A GitHub repository cloned as a local R project - ✅ Mapbox + mapgl ready for interactive mapping - ✅ A working commit + push setup
🚀 Next Steps
- Learn basic
git
workflows in RStudio - Explore R Markdown and Quarto documents for map projects
- Clone example repos from classmates or the instructor
Need help? Reach out during lab or post in the course GitHub Discussions!