Linking GitHub and R

You can upload files directly to a GitHub repository in the GitHub web interface, but as you create more complex files and file structures, that’s not going to be a feasible way to manage your work. That strategy also overlooks most of the features of what GitHub is at its core - a version control system.

We might want to version our work for several reasons:

  • To keep track of changes we’ve made, so that we can track when code works and when we’ve broken it
  • To be able to share code with collaborators and work on the same files at the same time and then reconcile and combine work all together
  • To be able to share code and data publicly with others

All three of these rationales are important motivations within the context of our class. There are two strategies which you may want to try to integrate GitHub into your R workflow.

Using the GitHub Desktop Client

GitHub Desktop is an application that allows you to upload, download, and reconcile github repositories stored on your computer with your GitHub account. From GitHub desktop, you can create new repositories, download previously created repositories, and upload new versions of repository contents to the cloud.

Using RStudio’s integrated Github Functionality

RStudio has GitHub functionality built right in, which is very handy for integrating version control into your R workflow. Getting RStudio set up to work with GitHub can be a bit tedious, but once it is set up, it is straightforward to use. An outstanding resource to help you get GitHub integrated with R is Happy Git and GitHub for the useR. As the authors mention in a section titled appropriately Is It Going to Hurt?, integrating Git changes your workflow. However, since many of you are just starting to learn R, making this part of your typical workflow early on will be challenging, but less of a change from other ways of doing things.

Assuming you’ve already got R and RStudio installed on your system and have already set up a GitHub account, start here:

  1. Check to see if Git is installed on your computer, and if it isnt, Install Git.
  2. Associate git on your computer with your GitHub account.
  3. Install a Git client like GitHub Desktop.
  4. Connect to GitHub
  5. Connect RStudio to GitHub
  6. Get Started using GitHub integrated with R. This video shows you how to communicate with your Github repository using RStudio:

We will ease our way into using Github, and will also devote some time to troubleshooting in class. I promise, it’s going to make sense soon!