Scaffolding reproducible research

A template for reproducible research

Dr. Jerid Francom

Feb 16, 2024

Overview

  • GitHub account setup
  • Git and GitHub on RStudio setup
  • Complete Lab 04 using Git and GitHub

Setup

GitHub

GitHub

  • Get code in your email inbox
  • Select options (optional)


Git on RStudio

Git is already on your RStudio container. We do need to configure it.

  1. Open the terminal.
  2. Copy/ paste (and edit) the following commands:
git config --global user.name "Your github username"


git config --global user.email "your github email address"


git config --global credential.helper 'cache --timeout=10000000'


git config --global --list

If credential.helper appears on two lines, one being cache --timeout=3600, then unset it with:

sudo git config --system --unset credential.helper

Git on RStudio

Linking RStudio to GitHub

Open the Console tab and type:

library(usethis)
library(gitcreds)

create_github_token()

Opens a browser window to create a token.

Click “Generate token” and copy the token.

In the Console tab, type:

gitcreds_set()

Paste the token and press Enter.

Git on RStudio (alternative)

Getting your GitHub token (without usethis)

  1. Go to the Tokens (classic) page on GitHub.
  2. Click “Generate new token”.
    1. Select “Generate new token (classic)”
  3. Complete the following:
    1. Name the token
    2. Change expiration to 90 days.
    3. Select repo, workflow, gist, and user scopes.
  4. Click “Generate token”.
  5. Copy the token to your clipboard.

Git on RStudio (alternative)

Setting your credentials in RStudio (without gitcreds)

In the RStudio Console tab, type:

library(credentials)

git_credential_ask()

Ignore the warning message after loading the package.

  • In the username field, type your GitHub username.
  • In the password field, paste the GitHub token you copied.

Using Git and GitHub

Local/ Remote scenarios

Scenario B: Fork a repository

  • Go to the Lab 04 repository
  • Click on the “Fork” button
  • (No need to change the repo name)
  • Click “Create Fork”

Scenario B: Clone a repository

  • Go to the repository you forked
    should happen automatically
  • Copy the repo URL
  • Open RStudio
  • Create new project from version control

Scenario B: Edit, commit, and push

Test the setup by making a change to the README.md file.

  • Edit the README.md file
  • Stage the changes
  • Commit the changes
  • Push the changes to the remote repository

Scenario B: Verify changes on GitHub

We can see that our changes are reflected on GitHub

  • Number of commits increases
  • The changed files show time of last change
  • The changes are visible in the README.md file

Discussions/ Issues

We have a course hub for Discussions. You can add Issues to repos.

Discussion

  • Ask questions
  • Share ideas
  • Get feedback

Issues

  • Enable in the repo settings
  • Create issues/ problems/ bugs
  • Assign to collaborators
  • Reference lines of code
  • Reference commits

GitHub roster

Student Developer Pack (optional)

References

Csárdi, Gábor. 2022. Gitcreds: Query ’Git’ Credentials from ’r’. https://CRAN.R-project.org/package=gitcreds.
Ooms, Jeroen. 2023. Credentials: Tools for Managing SSH and Git Credentials. https://CRAN.R-project.org/package=credentials.
Wickham, Hadley, Jennifer Bryan, Malcolm Barrett, and Andy Teucher. 2023. Usethis: Automate Package and Project Setup. https://CRAN.R-project.org/package=usethis.