10:00
Lecturer in Health Data Science within Centre for Health Informatics, Computing, and Statistics.
Academic background in statistics, with experience in data science consultancy and training.
Using R for over 10 years, and author of multiple R packages.
Combines slides, live coding examples, and exercises for you to participate in.
Ask questions throughout!
I hope you end up with more questions than answers after this workshop!
Course website: nrennie.rbind.io/training-git-r
Imagine:
code.R
.code_Nicola_comments.R
.code_v2.R
.code_v2_Nicola_comments.R
.Git: a free, open source version control tool that you install on your laptop.
GitHub / GitLab / BitBucket: a place to host online Git repositories, which allows people in different locations to work together on the code.
GitHub* allows you to:
*or other online repository hosting services
GitHub repositories can be private or public:
Add a license file to explain how other people can use your code
Use .gitignore
and GitHub secrets to make sure you never accidentally upload data or sensitive information like passwords.
What you need:
R, RStudio, and Git installed on your laptop
A GitHub account
GitHub credentials
Optional (but strongly recommended):
The usethis
R package
Make sure git is talking to R
Create a token
Set the token
Create a GitHub account if you don’t already have one, and make sure you have Git installed on your laptop.
Install and load the usethis
and gitcreds
packages.
Configure git then run create_github_token()
, and follow the instructions to generate a token.
Run gitcreds_set()
and paste in the token when prompted.
Hint: Open happygitwithr.com/https-pat!
10:00
Image: allisonhorst.com/git-github
Create a GitHub repository
Create a new R project
Clone the repository
Create a GitHub repository.
Create a new R project, and clone the repository.
10:00
Image: Openscapes blog GitHub for supporting, contributing, and failing safely by Allison Horst and Julia Lowndes.
Image: Openscapes blog GitHub for supporting, contributing, and failing safely by Allison Horst and Julia Lowndes.
Commit often
Make frequent commits. Otherwise, if you make a mistake, it’s harder to roll back to the version that works.
Image: allisonhorst.com/git-github
Committing changes
.gitignore
files
Push changes
Commit the initial files created when making a project.
Download the Hypoxia.csv
file above and save it into a folder called data
in your git project. Download the analysis.R
file and it to the project as well.
Add the data
folder to your .gitignore
file.
Commit and push your changes, and view them on GitHub.
10:00
Image: Openscapes blog GitHub for supporting, contributing, and failing safely by Allison Horst and Julia Lowndes.
Use descriptive branch names
Branches should be for a specific feature (not person!)
Regularly sync with the main branch
Delete merged branches
Creating a branch
Making and committing changes
Pushing changes to a remote branch
Making a pull request
Create a new branch from RStudio.
Make an edit to your R script and commit the changes.
Push your new branch to GitHub and open a pull request.
10:00
Image: allisonhorst.com/git-github
Creating a conflict
Pulling changes request
Fixing merge conflicts
Merging pull requests
Use the web editor to make a change on main
.
Return to your pull request and fix any merge conflicts.
Merge the pull request and delete the new branch.
10:00
Write a README.md
file!
A README file is a documentation file that provides an overview of a project. It typically includes key information such as:
See jcken95.github.io/projects/code_review.html for some good advice!
README.md files
Create a branch and commit some changes
Create a pull request
Request a review
Adding contributors
Create a new branch and edit your R script in some way (e.g. add some code or comments)
Commit your changes, open a pull request, and describe the changes.
Request a review from someone else in the room (and vice versa).
Note: you may need to add them as a collaborator to the repository. (You can remove them afterwards.)
Review someone else’s code - leave comments and decide whether to approve.
Bonus: add a README.md file to your repository, with a brief summary of the project and stating what packages and version of R you have used.
10:00
GitHub Issues/Discussions
GitHub profile README
GitHub Pages
GitHub Actions
Course website: nrennie.rbind.io/training-git-r