Git, GitHub & RStudio

RStudio users can leverage git Version control to enhance 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()
use_github()       # Connect local repo to GitHub

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::git_sitrep()
usethis::use_git_config(user.name = "Jane Doe", user.email = "jane@example.com")
gh::git_sitrep()

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.

Containerize your repository with binder.org using the holepunch package.

Quick_Publish your code in a binder.org container

Use the holepunch package

Bespoke_Publish your code in a binder

I recently found my QuickPublish approach didn’t quite work. So I RTFMed the binder.org docs and it seemed to imply a preference for NOT using a .binder/Dockerfile. Therefore, here is an approach that is slightly less automated but more bulletproof.

Step 1

holepunch::write_compendium_description()  # output is a DESCRIPTION file in the project root
holepunch::write_runtime()    # output is .binder/runtime.txt
holepunch::write_install()    # output is .binder/install.R
holepunch::generate_badge()   # output is a badge to be found in the README file(s)

Step 2

  1. Edit the .binder/install.R file using the following model.
  2. Edit the binder/install.R file based on this model or the documentation
  3. Edit the DESCRIPTION file using this basic model. Modify all the fields. You may want to base the Depends and Remotes sections on your .binder/install.R file

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

Corrections

If you see mistakes or want to suggest changes, please create an issue on the source repository.

Reuse

Text and figures are licensed under Creative Commons Attribution CC BY-NC 4.0. Source code is available at https://github.com/data-and-visualization/git-tutorial, unless otherwise noted. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".