Setting up Git/GitHub to work with R/RStudio can be challenging.

Here's a thread to walk you through the process step by step.

This thread also lives in blog post form. #rstats

Preamble: the best overall resource, and one I rely on extensively, is Happy Git with R by @JennyBryan and @jimhester_.

If you have additional questions about Git/GitHub + R/RStudio, this should be your first destination.

https://t.co/C7JHg8Fswb
The first step to set things up is to install Git.

Chapter 6 of Happy Git with R lays out the process for Mac, Windows, and Linux users.

https://t.co/AhzoudgIjE
I’m on a Mac so Git came pre-installed on my computer. I was able to verify that I had Git installed using the terminal in RStudio.
The next step is to configure Git.

This is covered in Chapter 7 of Happy Git with R , though I show what I believe to be a slightly easier process using the edit_git_config() function from the {usethis} package.
Now that you’ve installed and configured Git, you can use it locally.

The use_git() function will add a Git repository (often referred to as a “repo”) to an existing RStudio project.
Now that my RStudio project has an associated Git repository, I’ll see an extra tab on the top right: the Git tab.

From here, I can see the entire history of changes to my code over time (not many yet!).
Git doesn’t automatically track changes the way a tool like Google Docs does.

Instead, you have to tell Git: I made changes and I want you to keep a record of them.

Telling Git this is called making a commit and you can do it from within RStudio.
Each commit has a commit message, which is helpful because, when you look at your code history, you see what you did at each point in time (i.e. at each commit).

RStudio has a built-in tool to view your code history.
The process so far has enabled us to use Git locally.

But what if we want to connect to GitHub? How do we do that?
The first step is to sign up for a (free) GitHub account.

https://t.co/dqfYpbzTz7
Now you’ll need to enable RStudio to talk to GitHub. The process for doing so has recently changed (this is where I see the largest major difference from Happy Git with R).

The best way to connect RStudio and GitHub is using your username and a Personal Access Token (PAT).
To generate a personal access token, use the create_github_token() function from {usethis}. This will take you to the appropriate page on the GitHub website, where you’ll give your token a name and copy it (don’t lose it because it will never appear again!).
Now that you’ve created a Personal Access Token, we need to store it so that RStudio can access it and know to connect to your GitHub account.
The gitcreds_set() function from the {gitcreds} package will help you here.

You’ll enter your GitHub username and the Personal Access Token as your password (NOT your GitHub password, as I initially thought).

Once you’ve done all of this, you have connected RStudio to GitHub!
Now that we’ve connected RStudio and GitHub, let’s discuss how to make the two work together.

The basic idea is that you’ll set up projects you create in RStudio with associated GitHub repositories. Each RStudio project lives in a single GitHub repo.
How do we connect an RStudio project to a GitHub repo? Happy Git with R goes over three strategies (https://t.co/IkH3OVr7N9).

I’ll demonstrate two of them.
Sometimes you already have a project locally and you want to get it on GitHub. To do this, you’ll use the use_git() function from {usethis}, as we did above.
Then, you can use the use_github() function, which will create a GitHub repo and connect it to your RStudio project.
The most straightforward way to use RStudio and GitHub together is to create a repo on GitHub first.

Create the repo, then when you start a new project in RStudio, use the version control option, enter your repo URL, and you’re good to go.
You're all set now!

Reminder that there is a blog post form on this thread.

https://t.co/DwQ7ibM3pd
The blog post covers a bit more of the what and why of using a Git/GitHub workflow.

But I'm far from a Git/GitHub expert. To learn from those who know more, here are a few resources.
If you’re looking to learn more and I haven’t yet beat into you the idea that you should check out Happy Git with R, let me try it once more. It’s the best book to help guide you as you go deeper with using Git/GitHub in your R work.

https://t.co/m3lIngyihs
You also might check out Collaborating with git and GitHub by @datalorax_, @_bcullen, and @HOuafaa.

This chapter from the course materials for Social Data Science with R at the University of Oregon covers the basics of Git and GitHub.

https://t.co/zq94ShFEYQ
There's also materials by @juliesquid and @allison_horst from their 2019 rstudio::conf R for Excel Users workshop, which cover “version control and ... streamlines working with our most important collaborator: Future You.”

https://t.co/TR7hPjd9Vk

More from Tech

The entire discussion around Facebook’s disclosures of what happened in 2016 is very frustrating. No exec stopped any investigations, but there were a lot of heated discussions about what to publish and when.


In the spring and summer of 2016, as reported by the Times, activity we traced to GRU was reported to the FBI. This was the standard model of interaction companies used for nation-state attacks against likely US targeted.

In the Spring of 2017, after a deep dive into the Fake News phenomena, the security team wanted to publish an update that covered what we had learned. At this point, we didn’t have any advertising content or the big IRA cluster, but we did know about the GRU model.

This report when through dozens of edits as different equities were represented. I did not have any meetings with Sheryl on the paper, but I can’t speak to whether she was in the loop with my higher-ups.

In the end, the difficult question of attribution was settled by us pointing to the DNI report instead of saying Russia or GRU directly. In my pre-briefs with members of Congress, I made it clear that we believed this action was GRU.

You May Also Like

And here they are...

THE WINNERS OF THE 24 HOUR STARTUP CHALLENGE

Remember, this money is just fun. If you launched a product (or even attempted a launch) - you did something worth MUCH more than $1,000.

#24hrstartup

The winners 👇

#10

Lattes For Change - Skip a latte and save a life.

https://t.co/M75RAirZzs

@frantzfries built a platform where you can see how skipping your morning latte could do for the world.

A great product for a great cause.

Congrats Chris on winning $250!


#9

Instaland - Create amazing landing pages for your followers.

https://t.co/5KkveJTAsy

A team project! @bpmct and @BaileyPumfleet built a tool for social media influencers to create simple "swipe up" landing pages for followers.

Really impressive for 24 hours. Congrats!


#8

SayHenlo - Chat without distractions

https://t.co/og0B7gmkW6

Built by @DaltonEdwards, it's a platform for combatting conversation overload. This product was also coded exclusively from an iPad 😲

Dalton is a beast. I'm so excited he placed in the top 10.


#7

CoderStory - Learn to code from developers across the globe!

https://t.co/86Ay6nF4AY

Built by @jesswallaceuk, the project is focused on highlighting the experience of developers and people learning to code.

I wish this existed when I learned to code! Congrats on $250!!