-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path3-git.Rmd
153 lines (109 loc) · 3.47 KB
/
3-git.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
---
title: "Reproducable & collaborative research with git"
author: "Devin Judge-Lord"
date:
# output:
# html_document:
# toc: true
output:
xaringan::moon_reader:
lib_dir: libs
mathjax: "https://cdn.bootcss.com/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"
css: templates/xaringan-themer.css
# css: [default, default, rladies-fonts]
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
text_font_size: 2em
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
## Sets defaults for R chunks
knitr::opts_chunk$set(echo = TRUE, # echo = TRUE means that your code will show
warning=FALSE,
message=FALSE,
fig.retina = 2,
fig.align = "center",
dpi = 100,
# fig.path='Figs/', ## where to save figures
fig.height = 3,
fig.width = 3)
library(here)
source(here("setup.R"))
```
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 here}
## This works no matter where a script is saved in the project folder
library(haven)
d <- read_dta(here("data/EX1.dta"))
glimpse(d)
```
**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 "[email protected]
```
(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