class: center, middle, inverse, title-slide # Reproducable & collaborative research with git ### Devin Judge-Lord --- class: center ![](Figs/git-fire.png) --- ## Keep everything in one folder. - Portability - Replication - Transparency -- ## Track version history. - Restore code that breaks - See what you or others did (e.g. why did our results change?!?) --- ## Collaborating #### With git-users - Line-by-line merging/diff (code and writing) #### With non-users - Share document URLs (Word, LaTeX, whatever) - Merge in their changes (LaTeX) - Share HTML project updates (summary stats, draft figures, to-do lists) - [Share data](https://github.com/jtleek/datasharing) --- ## Repositories == Project folders ### + Subfolders #### /data #### /figs #### /functions #### /scratchpad **Tip:** Use `source(setup.R)` in all scripts, where `setup.R` is a script that loads the packages and functions used in your project. --- ## Finding things `here()` makes valid file paths: [Ode to the here() package](https://github.com/jennybc/here_here) ```r ## This works no matter where a script is saved in the project folder library(haven) d <- read_dta(here("data/EX1.dta")) glimpse(d) ``` ``` ## Observations: 20 ## Variables: 2 ## $ terms <dbl> 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6,… ## $ Leg_Act <dbl> 2, 2, 9, -4, 7, 20, 9, 0, 11, 12, 0, 11, 16, 5, 9, 5, 6,… ``` **NEVER** use `setwd()` or user-specific file paths (e.g. `"C:\Users\path\that\only\I\have"`)! --- ## Naming things! **NEVER** name files untitled.R, data.csv, ProblemSet.Rmd, Rplot.png! <img height="600px" src="Figs/naming-animals.png"> --- ## Basics ### To get started: `git clone repositiory.url` in the terminal/consol. (or, in RStudio, File -> New Project -> Version Control -> Git) ```{} git config --global user.name "yourGitHubUserName" git config --global user.email "yourEmail@email.com ``` (these do need to be done in the terminal/consol) See a more details [here](http://r-pkgs.had.co.nz/git.html) and [this blog post](https://www.r-bloggers.com/rstudio-and-github/) for more detailed instructions for git setup in RStudio. --- ## To do frequently - `git commit` - confirm your changes - `git pull` - merge in others' changes - `git push` - update online repository ![](https://imgs.xkcd.com/comics/git_commit.png) --- ## Avoid - Useless commit messages - Committing files > 100MB --- ## Troubleshooting - `git checkout` - restore a file from the online repo. - `git reset` - read up on this before you do it! ![](https://imgs.xkcd.com/comics/git.png) --- ## [GitHub](https://GitHub.com) ### Easily build a website - Repository -> Settings -> GitHub Pages ### [GitHub pro is free for students](https://education.github.com/pack) - unlimited collaborators on private repositories