exclude: true --- class: title_bg .title[ Using git and GitHub in the Classroom ] .conference[ .name[ ECME, April 2020 ] .bitly[ ] ] .author[ .name[ Colin Rundel ] .school[ Univ of Edinburgh ] ] --- class: middle, center ## Teaching Reproducible Workflows --- ## Reproducible vs Replicable <img src="imgs/leek_repro.jpeg" width="50%" style="display: block; margin: auto;" /> .footnote[ Source: Patil, Peng, Leek (2019) A visual tool for defining reproducibility and replicability. <i>Nature Human Behaviour</i> ] --- ## Reproducibility as a trust scale <br/><br/> <img src="imgs/trustscale3.png" width="100%" style="display: block; margin: auto;" /> <br/><br/><br/> .footnote[ Source: Gabriel Becker - <a href="https://gmbecker.github.io/MayInstituteKeynote2019/outline.html">Keynote</a> - Advanced R Course - May Institute for Computational Proteomics 2019 ] --- ## Reproducibility details <br/> - Are the tables and figures reproducible from the code and data? - Does the code actually do what you think it does? - In addition to what was done, is it clear *why* it was done? (e.g. how were hyper / tuning parameters chosen?) - Can the code be used for other data? - Can you extend the code to do other things? --- ## Reproducibility Toolchain <br/> .larger[ .center[ Scriptability `\(\rightarrow\)` R <br/> <br/> ] ] -- .larger[ .center[ Literate programming `\(\rightarrow\)` R Markdown <br/> <br/> ] ] -- .larger[ .center[ Version control `\(\rightarrow\)` `git` / GitHub <br/> <br/> ] ] --- class: middle, center ## Version Control --- ## What is version control? Version control is a (formal) system that records changes to a file (or a set of files) over time so that you can retrieve specific versions later. --- ## Minimal Version Control <img src="imgs/phd_comics_vc.gif" width="40%" style="display: block; margin: auto;" /> .footnote[ Source: [Piled Higher and Deeper](http://www.phdcomics.com) by Jorge Cham ] --- ## Version control systems - Start with a initial version of a document / file. - When you "save" just record the pieces of the file that changed. <img src="imgs/play-changes.png" width="25%" style="display: block; margin: auto;" /> - This creates a timeline for each and every file being tracked that lets you move backwards and forwards in time by adding or removing these diffs. - "Playing back" different sets of diffs onto the original document allows for multiple versions of any file to exist at the same time. <img src="imgs/merge.png" width="15%" style="display: block; margin: auto;" /> .footnote[ Source: [Software Carpentry](https://software-carpentry.org/). ] --- ## git > Git is a distributed version-control system for tracking changes in source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows. .footnote[ Source: Wikipedia - [git](https://en.wikipedia.org/wiki/Git). ] --- ## git in practice <img src="imgs/git_workflow.png" width="49%" /> <img src="imgs/git_memorize.jpg" width="49%" /> .footnote[ https://github.com/pcottle/learnGitBranching ] --- ## GitHub <img src="imgs/github_org.png" width="100%" /> --- class: center, middle # Some Terminology --- ## Repository (Repo) <img src="imgs/repo.png" width="100%" style="display: block; margin: auto;" /> --- ## History <img src="imgs/history.png" width="100%" style="display: block; margin: auto;" /> --- ## Commit <img src="imgs/commit.png" width="100%" style="display: block; margin: auto;" /> --- class: center, middle # In the classroom --- ## Context * Last semester I was the course organizer for Math 11176 - Statistical Programming * MSc course w/ ~200 students enrolled * Multiple marked assignments (both individual and team based) * For each assignment we distribute: * Instruction document * Template `Rmd` for solutions * Data and other support files * Need to collect: * Completed template `Rmd` * Rendered output (`pdf`, `html`, `md`, etc.) --- ## GitHub Structure * 1 organization / course * Students are added as (anonymous) members of the organization * 1 template repo / assignment * 1 private repo / assignment / (team | individual) * Automate the distribution, collection, and feedback using GitHub's API --- ## Template Example - hw1 <img src="imgs/github_hw1.png" width="100%" style="display: block; margin: auto;" /> --- class: center, middle ## Using `ghclass` --- ## Creating a team assignment ```r org_create_assignment( org = "ghclass-demo", repo = c("hw01-team01", "hw01-team01", "hw01-team02", "hw01-team02"), user = c("ghclass-anya", "ghclass-bruno", "ghclass-celine", "ghclass-diego"), team = c("hw01-team01", "hw01-team01", "hw01-team02", "hw01-team02"), source_repo = "statprog-s1-2019/hw1" ) ``` ``` ## ✓ Mirrored 'statprog-s1-2019/hw1' to 'ghclass-demo/hw01-team01'. ``` ``` ## ✓ Mirrored 'statprog-s1-2019/hw1' to 'ghclass-demo/hw01-team02'. ``` ``` ## ✓ Created team 'hw01-team01' in org 'ghclass-demo'. ``` ``` ## ✓ Created team 'hw01-team02' in org 'ghclass-demo'. ``` ``` ## ✓ Added 'ghclass-anya' to team 'hw01-team01'. ``` ``` ## ✓ Added 'ghclass-bruno' to team 'hw01-team01'. ``` ``` ## ✓ Added 'ghclass-celine' to team 'hw01-team02'. ``` ``` ## ✓ Added 'ghclass-diego' to team 'hw01-team02'. ``` ``` ## ✓ Added team 'hw01-team01' to repo 'ghclass-demo/hw01-team01'. ``` ``` ## ✓ Added team 'hw01-team02' to repo 'ghclass-demo/hw01-team02'. ``` .footnote[ [demo](https://github.com/ghclass-demo/hw01-team01) ] --- ## Creating an individual assignments ```r user = c("ghclass-anya", "ghclass-bruno", "ghclass-celine", "ghclass-diego") org_create_assignment( org = "ghclass-demo", repo = paste0("proj1-", user), user = user, source_repo = "statprog-s1-2019/proj1" ) ``` ``` ## ✓ Mirrored 'statprog-s1-2019/proj1' to 'ghclass-demo/proj1-ghclass-anya'. ``` ``` ## ✓ Mirrored 'statprog-s1-2019/proj1' to 'ghclass-demo/proj1-ghclass-bruno'. ``` ``` ## ✓ Mirrored 'statprog-s1-2019/proj1' to 'ghclass-demo/proj1-ghclass-celine'. ``` ``` ## ✓ Mirrored 'statprog-s1-2019/proj1' to 'ghclass-demo/proj1-ghclass-diego'. ``` ``` ## ✓ Added user 'ghclass-anya' to repo 'ghclass-demo/proj1-ghclass-anya'. ``` ``` ## ✓ Added user 'ghclass-bruno' to repo 'ghclass-demo/proj1-ghclass-bruno'. ``` ``` ## ✓ Added user 'ghclass-celine' to repo 'ghclass-demo/proj1-ghclass-celine'. ``` ``` ## ✓ Added user 'ghclass-diego' to repo 'ghclass-demo/proj1-ghclass-diego'. ``` .footnote[ [demo](https://github.com/ghclass-demo/proj1-ghclass-anya) ] --- ## Update files ```r repo_add_file(repo = org_repos(org = "ghclass-demo", filter = "hw01-"), file = "files/fizzbuzz.png", overwrite = TRUE) ``` ``` ## ✓ Added file 'fizzbuzz.png' to repo 'ghclass-demo/hw01-team01'. ``` ``` ## ✓ Added file 'fizzbuzz.png' to repo 'ghclass-demo/hw01-team02'. ``` ```r repo_add_file(repo = org_repos(org = "ghclass-demo", filter = "hw01-"), file = "files/data.csv", overwrite = TRUE) ``` ``` ## ✓ Added file 'data.csv' to repo 'ghclass-demo/hw01-team01'. ``` ``` ## ✓ Added file 'data.csv' to repo 'ghclass-demo/hw01-team02'. ``` .footnote[ [demo](https://github.com/ghclass-demo/hw01-team01) ] --- ## Collect student work ```r local_repo_clone(repo = org_repos(org = "ghclass-demo", "hw01-"), local_path = "hw01") ``` ``` ## ✓ Cloned 'ghclass-demo/hw01-team01'. ``` ``` ## ✓ Cloned 'ghclass-demo/hw01-team02'. ``` -- <img src="imgs/github_clone.png" width="65%" style="display: block; margin: auto;" /> --- ## Contributor statistics ```r repo_contributors(repo = "statprog-s1-2019/hw02-lab01-team03") %>% mutate(username = LETTERS[1:4]) %>% arrange(desc(commits)) ``` ``` ## # A tibble: 4 x 3 ## repo username commits ## <chr> <chr> <int> ## 1 statprog-s1-2019/hw02-lab01-team03 D 8 ## 2 statprog-s1-2019/hw02-lab01-team03 C 5 ## 3 statprog-s1-2019/hw02-lab01-team03 B 4 ## 4 statprog-s1-2019/hw02-lab01-team03 A 3 ``` ```r repo_contributors(repo = "statprog-s1-2019/hw02-lab01-team10") %>% mutate(username = 1:5) %>% arrange(desc(commits)) ``` ``` ## # A tibble: 5 x 3 ## repo username commits ## <chr> <int> <int> ## 1 statprog-s1-2019/hw02-lab01-team10 5 17 ## 2 statprog-s1-2019/hw02-lab01-team10 4 9 ## 3 statprog-s1-2019/hw02-lab01-team10 3 4 ## 4 statprog-s1-2019/hw02-lab01-team10 1 1 ## 5 statprog-s1-2019/hw02-lab01-team10 2 1 ``` --- class: middle, center ## GitHub Actions .footnote[ [demo](http://github.com/ghclass-demo/hw01-team01) ] --- background-image: url("imgs/github_badge.png") background-position: center background-size: contain --- background-image: url("imgs/github_actions_result.png") background-position: center background-size: contain --- background-image: url("imgs/github_actions.png") background-position: center background-size: contain --- ## Ongoing and future work * Peer evaluation (Mine and Therese Anders) * Automated rendering * Automated report generation / assignment dashboards * Structured assignments * Code similarity comparisons