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

Recently, the @CNIL issued a decision regarding the GDPR compliance of an unknown French adtech company named "Vectaury". It may seem like small fry, but the decision has potential wide-ranging impacts for Google, the IAB framework, and today's adtech. It's thread time! 👇

It's all in French, but if you're up for it you can read:
• Their blog post (lacks the most interesting details):
https://t.co/PHkDcOT1hy
• Their high-level legal decision: https://t.co/hwpiEvjodt
• The full notification: https://t.co/QQB7rfynha

I've read it so you needn't!

Vectaury was collecting geolocation data in order to create profiles (eg. people who often go to this or that type of shop) so as to power ad targeting. They operate through embedded SDKs and ad bidding, making them invisible to users.

The @CNIL notes that profiling based off of geolocation presents particular risks since it reveals people's movements and habits. As risky, the processing requires consent — this will be the heart of their assessment.

Interesting point: they justify the decision in part because of how many people COULD be targeted in this way (rather than how many have — though they note that too). Because it's on a phone, and many have phones, it is considered large-scale processing no matter what.
Next.js has taken the web dev world by storm

It’s the @reactjs framework devs rave about praising its power, flexibility, and dev experience

Don't feel like you're missing out!

Here's everything you need to know in 10 tweets

Let’s dive in 🧵


Next.js is a @reactjs framework from @vercel

It couples a great dev experience with an opinionated feature set to make it easy to spin up new performant, dynamic web apps

It's used by many high-profile teams like @hulu, @apple, @Nike, & more

https://t.co/whCdm5ytuk


@vercel @hulu @Apple @Nike The team at @vercel, formerly Zeit, originally and launched v1 of the framework on Oct 26, 2016 in the pursuit of universal JavaScript apps

Since then, the team & community has grown expotentially, including contributions from giants like @Google

https://t.co/xPPTOtHoKW


@vercel @hulu @Apple @Nike @Google In the #jamstack world, Next.js pulled a hefty 58.6% share of framework adoption in 2020

Compared to other popular @reactjs frameworks like Gatsby, which pulled in 12%

*The Next.js stats likely include some SSR, arguably not Jamstack

https://t.co/acNawfcM4z


@vercel @hulu @Apple @Nike @Google The easiest way to get started with a new Next.js app is with Create Next App

Simply run:

yarn create next-app

or

npx create-next-app

You can even start from a git-based template with the -e flag

yarn create next-app -e https://t.co/JMQ87gi1ue

https://t.co/rwKhp7zlys

You May Also Like