Estimated Time to Complete: 60 minutes

Learning Goals

  1. Install Git, GitHub Desktop, Box Drive, Box Tools, R, R Studio
  2. Get access to the WWS GitHub
  3. Connect R with Git

Starting with the Basics

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.


Step 1: R and R Studio

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.

  1. Download R: https://cran.rstudio.com/

  2. Run the R installer: Keep all default settings.

  3. Download RStudio: https://posit.co/download/rstudio-desktop/

  4. Run the RStudio installer: Keep all default settings.

  5. Check installation

    • Open RStudio
    • Type the following in the console: print("hello world")
    • Hit enter
    • Should print back hello world without errors
  6. If 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:


Step 2: Git

What is Git and why use it?

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

Install Git

  1. Download Git for Windows: git-scm.com/install/windows

    • If you’re using a different operating system check out this resource on how to set up Git.
    • Note: Do not use Firefox brower for this step.
  2. Run the installer:

    1. When asked about Adjusting your PATH environment, make sure to select “Git from the command line and also from 3rd-party software”. Otherwise, accept the defaults.
  3. 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.

  4. If you’ve just installed Git and RStudio can’t find it:

    1. 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.

    2. Close RStudio and reopen it. Try Step 3 again.


Create a GitHub Account

  1. If needed sign up for a (free) GitHub account (https://github.com/).
  2. Ensure you have access to the WWS GitHub
    • If you don’t have access, send your email to
    • Check your email to accept the invite to the organization

Tell Git Who You Are

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")

Step 3: Connect RStudio to GitHub

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.

  1. 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:

  2. 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.

  3. 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!

  4. 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()

Step 5: Install Box Drive

  1. Go here and install Box Drive and Box Tools

Step 6: Check Documents Folder Location

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.

  1. Navigate to: This PC → Windows (C:) → Users → your username → Documents

  2. 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/

  3. Pin to quick access. It’s recommended that your store your repositories here.


You’re All Set!

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


More Resources