Git, GitHub & RStudio

RStudio users can leverage git Version-control which enhances reproducibility.

The usethis package and the RStudio IDE will help you orchestrate your version control repositories as RStudio projects.

Setup

To get started, make a free GitHub.com account. Make sure you have the latest versions of R, RStudio, and usethis. Then, setup your RStudio configuration using two key documents: Setup, and Managing Git(Hub) Credentials.

Tips

Clone or fork from GitHub

usethis::create_from_github("https://github.com/data-and-visualization/git-tutorial")

Create the GitHub repo from local

library(usethis)
use_git()          # initialize a git repo
use_git_ignore()
use_readme.Rmd()
use_ccby_license()
# Before next step  → stage & commit changes
use_github()       # Connect local repo to GitHub

Rename default branch

library(usethis)
git_default_branch()
git_default_branch_rename()
git_default_branch_rediscover()

set-up git and manage GitHub credentials

# Sign-in to your GitHub account
# Read: https://usethis.r-lib.org/articles/articles/git-credentials.html
# Read: https://usethis.r-lib.org/articles/articles/usethis-setup.html
usethis::create_github_token()
gitcreds::gitcreds_set()
gh::gh_whoami()
usethis::gh_token_help()
usethis::use_git_config(user.name = "Jane Doe", user.email = "jane@example.com")
usethis::gh_token_help()

Next Level…

Take your reproducibility to the next level. Make your code citable by connecting your GitHub repo and your ORCID (unique author ID) through to the Zenodo archival repository. Now, every time you commit a milestone release, you also mint a DOI.

Share a zero-install compute environment

Publish your code in a binder.org container

  • Full documentation to create a sharable RStudio compute environment is documented on this Quarto page about projects.

  • The key elements are an install.R and runtime.txt files. The content and format of each file is demonstrated properly at the GitHub repo. Browse and you will see.

  • In summary, at the Terminal, type: quarto use binder

Hints

Generate a binder badge with usethis::use_binder_badge(urlpath = "rstudio"). This should store the badge in your GitHub’s project README file. Then commit and push your changes to GitHub; go to the README on GitHub, launch the build and wait for the long launch/build time.

Hint: be prepared to wait. The first build can take some time. Sometimes you must launch an initial or dormant build more than once. In my experienced these hiccups are rare, but try the launch twice before getting involved in extensive troubleshooting.


The old documentation from this site can be found in the v.0.2019 release on GitHub.