Estimated Time to Complete: 60 minutes
Everyone is coming into this workshop with different levels of experience using R and Git, and some topics may feel basic. Don’t tune out, going back to the basics you might learn small new things you never knew, and your experience can be helpful to others who are learning this for the first time.
The goal is that by the end, everyone is working from the same set of skills and practices for managing, storing, and maintaining our data.
R has some great tools that help make using Git easier. It’s also a great tool for reproducible analysis.
R is the coding language and will work on its own, but it’s relatively unfriendly. RStudio provides a visual, user friendly interface to use R.
Download R: https://cran.rstudio.com/
Run the R installer: Keep all default settings.
Download RStudio: https://posit.co/download/rstudio-desktop/
Run the RStudio installer: Keep all default settings.
Check installation
print("hello world")enterhello world without errorsIf you’ve already got R and RStudio installed:
Double check your R and RStudio versions are up to date.
Ensure your R packages are updated:
Git is a tool that helps you:
Keep backups: If your computer is lost or damaged, you can get your files back from GitHub.
Track changes: See what you changed, when, and why. No more saving 10 versions of the same file.
Collaborate: Work with others without overwriting each other’s work.
Recommended video
Alice Bartlett explains Git for beginners:
Slides from her talk
Download Git for Windows: git-scm.com/install/windows
Run the installer:
Check it worked:
In RStudo, go to the terminal tab
Type: git --version
If you see a version number, you’re good. If not, try again or ask for help.
If you’ve just installed Git and RStudio can’t find it:
Go to Tools → Global Options → Git/SVN → under Git Executable
paste the path to the git.exe file. For Windows this should
be: C:/Program Files/Git/bin/git.exe.
Close RStudio and reopen it. Try Step 3 again.
Run these commands in RStudio (replace with your name and the email you used for GitHub):
#install.package("usethis") #only run once to install package
library(usethis)
usethis::use_git_config(user.name = "Your Git Username Here",
user.email= "Your Email Here")
Now we’ll link your GitHub account to RStudio. To do this you need to get an access token from GitHub. This is a long string of characters (basically a password) that connects RStudio to GitHub.
Check if you already have one:
#install.packages(gitcreds) #run the first time
library(gitcreds)
## Warning: package 'gitcreds' was built under R version 4.4.2
gitcreds::gitcreds_get()
## <gitcreds>
## protocol: https
## host : github.com
## username: katiewampler
## password: <-- hidden -->
If your GitHub username shows up, you can skip ahead. If not:
Create a new token:
#install.packages(gitcreds) #run the first time
library(gitcreds)
usethis::create_github_token()
This will open GitHub in your browser, scroll down, click Generate token (green button), and copy it.
Store your token:
This is important as once your token is generated you can’t get it from GitHub again.
gitcreds::gitcreds_set()
When prompted for a password, paste your token. Done!
Ensure it worked
Once you’ve got your token, you can run the following lines in R to check that your credentials are stored correctly:
gitcreds::gitcreds_get()Similar to what RStudio does for R, GitHub Desktop gives you a friendlier interface for managing files using Git.
Download GitHub Desktop
Install and open the program.
Go to File → Options → Accounts and sign in to GitHub.
At OSU, the default is not the C Drive, which can create issues with file paths in R. We’ll go into more detail later, but we want to make sure you have a good folder to save your project to.
Navigate to: This PC → Windows (C:) → Users →
your username → Documents
If you don’t see the Documents folder, go to your
Documents folder in the Quick Access bar and copy it to
C:/Users/yourusername/
Pin to quick access. It’s recommended that your store your repositories here.
Now you can:
Save versions of your work without making endless copies
Restore old versions
Share work with others safely
Keep a backup online in case disaster strikes
Happy Git and GitHub for the useR: excellent beginner guide
Git for Humans – Alice Bartlett: friendly talk