-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.Rmd
632 lines (364 loc) · 10.9 KB
/
index.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
---
title: "Introduction to Reproducible Science"
subtitle: "Version Control using Git and Github"
author: "<br><br><br><br>François Leroy"
institute: "Czech Univeristy of Life Sciences<br>Prague"
# date: "2016/12/12 (updated: `r Sys.Date()`)"
output:
xaringan::moon_reader:
self_contained: true ## otherwise you need the entire folder to see the slides correctly
yolo: false
css: ["middlebury.css", "tamu-fonts.css"] ## Note that if you don't specify the .css after the file name here, xaringan will import and renew the template at each run in ./libs/remark-css/
lib_dir: libs
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
titleSlideClass: [top, left, inverse]
---
# Why is reproducible science important?
.pull-left[
<br><br>
- Paper by Reinhart & Rogoff (2010)
- Link between debt and GDP growth
- When $$debt > 90 \% = \text{GDP growth} \sim 0$$
- Used as an argument for austerity plans
]
.pull-right[
```{r, echo=F}
knitr::include_graphics("images/rr_article.PNG")
```
```{r, echo=F, out.width="90%"}
knitr::include_graphics("images/rr_barplot.PNG")
```
]
---
# Why is reproducible science important?
.pull-left[
<br><br>
- Paper by Reinhart & Rogoff (2010)
- Link between debt and GDP growth
- When $$debt > 90 \% = \text{GDP growth} \sim 0$$
- Used as an argument for austerity plans
<br><br><br>
.center[
CALCULATION ERROR!
ARBITRARY DECISIONS!
]
]
.pull-right[
```{r, echo=F}
knitr::include_graphics("images/rr_article.PNG")
```
```{r, echo=F, out.width="90%"}
knitr::include_graphics("images/rr_barplot.PNG")
```
]
---
# Pros of Reproducible Science
<br><br>
- **Transparency**: data, code and methods available allow verification
- **Quality assurance**: identification and correction make results more reliable
- **Facilitate collaborations**: see what are colleagues doing
- **Peer review**
- **Educational value**
- **Enhanced public trust**
???
The means have been computed in a weird way.
They didn't use some data that had a high GDP growth with a debt higher than a 100% (we don't know why)
The most important: there was as mistake in on of the excel formula
After correction: 2.2% instead of the 0%
--
<br><br>
.center[
**All of this using Git and Github**
]
---
# Version control: what is (G)it?
**Version Control:**
.center[
*Program responsible for managing changes to computer programs, documents, large
websites or other collection of information*
]
--
<br>
- Git was created Linus Torvalds in 2005
- You can backup versions (or "saves", like in a videogame) of a file/directory
- A version is called a **commit**
- Each commit is identified by a unique tag and a message
--
.pull-left[
<br><br>
**Allows you to come back to a specific commit**
]
.pull-right[
```{r, echo=F}
knitr::include_graphics("images/version_control.jpg")
```
]
---
class: inverse, center, middle
# GitHub
## A powerful tool for reproducible science
---
# GitHub
- **Online platform**: this is (just) the online version of Git. If you want to understand Github, you need first to understand Git
- **Repository hosting**: you can store and manage your files and their versions from any device
- **Collaborative features**: people can suggest modifications of your code (pull request)
- **Issues tracking**
- **Branching and merging between collaborators**
- **Code review**
- **Github pages**: create and host your website directly from a repository
---
class: inverse, center, middle
# How to use Git?
---
# Initialize your repository
<br>
- **Repository** ("repo") = directory that is version-controlled by Git, with files and history of their changes
--
<br>
- This is the very first necessary step
--
<br>
- For this, use `git init` in your Command Line Interface
--
<br>
- Now, a hidden directory `.git` can be found at the root of your project
--
<br>
.center[
**Don't ever modify this directory directly,<br>this is where all your backups are!!!!!**
]
---
# Your first commit
- First of all, the most useful command:
```
git status
```
--
Will tell you the *branch* you are on, the *deleted*, *modified*, *created* files, if the local commits are pushed, which changes are **staged**...
--
- **Stage** the changes using:
```
git add name_file_1 name_file_2 ... name_file_n # if you want to stage specific changes, or
git add . # if you want to stage every changes
```
--
- **Commit** using:
```shell
git commit # a text editor will open where you can write the commit message. Or,
git commit -m "Commit message" # if you want to write directly the commit message
```
---
# Branches
**Branch** = parallel line of development that diverges from the main line ("main" branch). Branches are used to isolate changes and work on new features or fixes without affecting the main codebase.
.pull-left[
<br><br>
```{r, echo=F}
knitr::include_graphics("images/branch.png")
```
]
--
.pull-right[
- At first, you will just see the branch `main`
```
git branch
* main
```
- You can create new branches
```
git branch new_branch_name
```
- And switch between branches
```
git checkout name_branch
Switched to branch 'name_branch'
```
]
---
# Merge and conflicts
.pull-left[
<br><br><br><br><br>
```{r, echo=F}
knitr::include_graphics("images/branch.png")
```
]
.pull-right[
- **Merge** branches together
From the `main` branch, use:
```
git merge new_branch
```
This combines changes from both branches into a new commit
- **Conflicts**: if a file is modified on two branches, Git can't decide which change to keep when merging, causing a **conflict**.
To resolve conflicts, manually edit the conflicted file, stage it with `git add`, continue the merge with `git merge --continue`, and commit the merge.
]
---
# Check your commits and changes
<br><br>
- List the commits using:
```
git log # or
git log --oneline # or
git reflog
```
You will see the **SHA** (Simple Hashing Algorithm = unique id of your commit), the author, date/time, commit message
--
<br><br>
- See the changes of a commit:
```
git show <SHA>
```
---
# Undo your commits
.center[
**There are different ways to do it but the most common one is reset**
]
--
- `git reset` is dangerous: you go back to the desired commit and "erase" all the commit created since
```
git reset --hard <SHA>
```
However, you can bypass this by using:
```
git reset --hard <previous-SHA>
git reset --soft <last-SHA>
```
--
- `git checkout` allows to create a temporary branch with the commit wanted
```
git checkout <SHA>
```
---
# Useful tips
**Ignore files**
- You can specify the files/directories that you never want to commit in the `.gitignore` file
--
<br>
**git stash**
- Saves the modifications you made after the last commit without having to make a commit using `git stash`
- List the stashes using `git stash list`
- You can bring back a specific stash using `git stash apply stash@{n}`
---
class: inverse, center, middle
# Moving on to
# GitHub
---
# Publish your local repository online
.pull-left[
- Create a repository on Github
<br><br>
- Click on the clipboad to copy the remote
]
.pull-right[
```{r, echo=F, out.width="30%"}
knitr::include_graphics(path = "images/repo-create.png")
```
<br>
![](images/copy-remote-repository-url-quick-setup.png)
]
--
- Now, `push` your existing repository from the command line:
```
git remote add origin https://github.com/user_name/repo_name.git
git branch -M main
git push -u origin main
```
--
<br>
.center[
**From now on, you will be able to publish your commits using** `git push`
**Also, you can dowload the modifications that are published on Github by using** `git pull`
]
---
# Large File Storage
- GitHub has a file size limit: 100 MB
- You can bypass this limit using **Git Large File Storage**
- You need to install the software ([here](https://git-lfs.com/))
- Specify the large files you want to track using `git lfs track images/*.png`
- This will create a file `.gitattributes`
- Next commit you'll do, the tracked large files will be handled in a specific way so you can push the commits online
---
# Clone a github repository
.center[
**Nothing more simple**
]
--
<br><br>
- Go on your favorite Github repository
<br><br>
- Copy the URL of this repository
<br><br>
- Clone it from the command line using:
```
git clone https://github.com/user_name/repo_name.git
```
---
# Forking a github repository
- A fork is a personal copy of a github repository
<br><br>
- It create a new independent repository that you can modify as much as you want, without modifying the original repo
<br><br>
- Also, you can ask to merge your modifications to the original repo using a `pull request`
---
# Github pages
- A really cool feature of Github is that you can create an HTML page for a repository
<br>
- For this, go in *Settings > Options > Github Pages*, select the branch and the folder that contains the .html file
<br>
- Github will automatically look for a file named `index.html` to build from
<br>
- If your html file is not called `index.html`, you can visit the URL provided by Github and add the name of the html file at the end (*e.g.* `URL/my_file.html`) and your website will be there!
<br>
- You also get one website per Github account @ `username.github.io`
---
class: inverse, center, middle
# Friendly user applications
### [<ins>Github desktop</ins>](https://desktop.github.com/)
### [<ins>Visual Studio Code</ins>](https://code.visualstudio.com/)
---
class: inverse, center, middle
# Thank you for your attention
## Now, install git from [<ins>here</ins>](https://git-scm.com/)
---
# Tips for git installation
* You can either spam `next` and then click `install`
.center[
**Or**
]
* Uncheck the `Additional icons` and `Windows Explorer integration` features (they are cumbersome)
.center[
```{r, echo=F, out.width="60%"}
knitr::include_graphics("images/git_setup.PNG")
```
]
---
# Tips for git installation
* Here you can choose the text editor used for commits, picking and squashing... By default, Git is set up to use Vim (and you need to know Vim commands to use it)
.center[
```{r, echo=F, out.width="60%"}
knitr::include_graphics("images/text_editor.PNG")
```
]
---
# Tips for git installation
* Last but not least: here you can set up Git in order to also use shell commands (and not only commands specific to your OS). It also allows the (very very) cool `Julia`'s feature to use shell commands directly in the `Julia` REPL
.center[
```{r, echo=F, out.width="60%"}
knitr::include_graphics("images/linux_cmd.PNG")
```
]
---
# One last thing
<br>
* If you just installed Git on your computer, it may come useful to specify your name and email address to Git using:
```
git config --global user.name "Your name"
git config --global user.email "address@domain"
```
<br>
* Now, you should be able to see these changes using:
```
git config --global --list
```