forked from privefl/R-presentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rstudio-git.html
438 lines (254 loc) · 13.9 KB
/
rstudio-git.html
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
<!DOCTYPE html>
<html>
<head>
<title>RStudio and Git</title>
<meta charset="utf-8">
<meta name="author" content="Florian Privé & Magali Richard" />
<meta name="date" content="2017-01-18" />
<link href="libs/remark-css/example.css" rel="stylesheet" />
</head>
<body>
<textarea id="source">
class: center, middle, inverse, title-slide
# RStudio and Git
## <a href="https://privefl.github.io/R-presentation/rstudio-git.html" class="uri">https://privefl.github.io/R-presentation/rstudio-git.html</a>
### Florian Privé & Magali Richard
### January 18, 2017
---
class: center, middle, inverse
# RStudio
---
## RStudio Features
- everything you can expect from a good IDE
- keyboard shortcuts I use
1. *Crtl + Space* (autocompletion)
2. *Ctrl + Up* (command history & search)
3. *Ctrl + Click* (function source code)
3. *Ctrl + Enter* (execute line of code)
4. *Ctrl + Shift + K* (knit)
4. *Ctrl + Shift + B* (build package or website)
4. *Ctrl + Shift + M* (pipe)
4. *Alt + Shift + K* to see all shortcuts
4. ...
- Panels (everything is integrated, including **Git**)
- **R Projects**
---
## Releases
- Version 1.0 (November 1st, 2016)
<ul>
<li>Authoring tools for <a href="http://rmarkdown.rstudio.com/r_notebooks.html">R Notebooks</a>.</li>
<li>Integrated support for the <a href="http://spark.rstudio.com">sparklyr</a> package (R interface to Spark).</li>
<li>Enhanced data import tools based on the <a href="https://github.com/hadley/readr">readr</a>, <a href="https://github.com/hadley/readxl">readxl</a> and <a href="https://github.com/hadley/haven">haven</a> packages.</li>
<li>Performance profiling via integration with the <a href="https://github.com/rstudio/profvis">profvis</a> package.</li>
<li>Authoring tools for R Markdown <a href="http://rmarkdown.rstudio.com/rmarkdown_websites.html">websites</a> and the <a href="https://bookdown.org/">bookdown</a> package.</li>
</ul>
- Version 1.1.383 (October 9th, 2017)
- integrated terminal
- new features for connections to data bases
- better object explorer (`View()`)
---
## R Projects
- **Meaningful structure** in one folder
- The working directory automatically switches to the project's folder.
- File tab displays the associated files and folders in the project
- History of R commands and open files.
- Any settings associated with the project, such as Git settings, are loaded.
- Note that a *set-up.R* or even a *.Rprofile* file in the project's root directory enable project-specific settings to be loaded each time people work on the project.
---
## Project-oriented workflow
<blockquote class="twitter-tweet" data-lang="fr" align="center"><p lang="en" dir="ltr">The only two things that make <a href="https://twitter.com/JennyBryan?ref_src=twsrc%5Etfw">@JennyBryan</a> 😤😠🤯. Instead use projects + here::here() <a href="https://twitter.com/hashtag/rstats?src=hash&amp;ref_src=twsrc%5Etfw">#rstats</a> <a href="https://t.co/GwxnHePL4n">pic.twitter.com/GwxnHePL4n</a></p>&mdash; Hadley Wickham (@hadleywickham) <a href="https://twitter.com/hadleywickham/status/940021008764846080?ref_src=twsrc%5Etfw">11 décembre 2017</a></blockquote>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
Read more at https://www.tidyverse.org/articles/2017/12/workflow-vs-script/
---
## More
Chapter [*Efficient set-up*](https://bookdown.org/csgillespie/efficientR/set-up.html) of
<img src="https://csgillespie.github.io/efficientR/figures/f0_web.png" width="45%" style="display: block; margin: auto;" />
---
class: center, middle, inverse
# Version control (Git)
## tracks changes to your code
---
## You don't use version control?
<br>
<img src="https://www.tacomaworld.com/attachments/i-also-like-to-live-dangerously-jpg.760853/" width="75%" style="display: block; margin: auto;" />
---
## Why should you use version control?
Have you ever:
- **Made a change to code, realised it was a mistake and wanted to revert back?**
- **Lost code or had a backup that was too old?**
- Had to maintain multiple versions of a product?
- Wanted to see the difference between two (or more) versions of your code?
- Wanted to prove that a particular change broke or fixed a piece of code?
- Wanted to review the history of some code?
- **Wanted to submit a change to someone else's code?**
- **Wanted to share your code, or let other people work on your code?**
- Wanted to see how much work is being done, and where, when and by whom?
- Wanted to experiment with a new feature without interfering with working code?
In these cases, and no doubt others, a version control system should make your life easier.
.footnote[Source: https://stackoverflow.com/a/1408464/6103040]
---
## Why should you use version control?
### Version control for the researcher
<img src="http://www.datacarpentry.org/rr-version-control/fig/phd101212s.png" width="45%" style="display: block; margin: auto;" />
---
## Why should you use version control?
### Version control for the data analyst: reproducible workflow
<center>
<iframe width="560" height="315" src="https://www.youtube.com/embed/s3JldKoA0zw" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
</center>
.footnote[Also, see https://stackoverflow.com/q/2712421/6103040]
---
## Why should you use version control?
### To work from anywhere
<img src="git.svg" width="85%" style="display: block; margin: auto;" />
---
## Why should you use version control?
### Working with GitHub, a line on your CV
<br>
> A lot of students have said to me later, even first-year undergraduates, that using GitHub has helped them a lot when they went for an internship or a research position interview.
> They are able to say, "Oh, I already have worked with GitHub. I'm familiar with it. I know how it works.” So I think they are at least able to put that on their CVs and go into a situation where there's a research or data analysis team and say, "Yeah, sure. I am actually familiar with the same tools that you use."
>
> -- Mine Cetinkaya-Rundel, Duke University, RStudio
.footnote[[Read more](https://github.com/blog/2336-invest-in-tools-students-can-grow-with-github-and-rstudio-for-data-science-at-duke-university)]
---
## Why should you use version control?
### To get a nice mosaic on GitHub
<img src="webshot-mosaic-github.png" width="80%" style="display: block; margin: auto;" />
---
## Why should you use version control?
### February session: Best coding practices
A. Arnaud & J. Arbel will focus on
- coding style
- R packages (RStudio & Git are super useful for developing!!)
<br>
### June session: Make your personal webpage with R
We will focus on using R Markdown & GitHub in order to easily make websites, presentations & reports, and make them available online.
---
## Git platforms (share your code, collaborate)
- [GitHub](https://github.com/magrichard), [documentation](https://guides.github.com/activities/hello-world/) (only free for public repositories)
- [GitLab UGA](https://gricad-gitlab.univ-grenoble-alpes.fr/), [documentation](https://docs.gricad-pages.univ-grenoble-alpes.fr/help/) or just [GitLab](https://about.gitlab.com/) (open source & free)
- [Bitbucket](https://bitbucket.org/) (free with less than 5 collaborators)
- any server..
---
## 3 main commands: commit, push, and pull
- pull: update your local project with the latest version of the main project
- commit: snapshot of your code at a specified point in time
- push: merge your local modifications with the main project
---
## Simple (solo) use of git to prevent merge conflicts
<br>
<img src="meme-merge-conflicts.jpg" width="90%" style="display: block; margin: auto;" />
---
## Simple (solo) use of git to prevent merge conflicts
### When you open a project, always pull
<img src="http://s2.quickmeme.com/img/73/730acd1051914ae6cb59ae7e751498c477bfd0191cc2a07f90682451dc1da9d5.jpg" width="60%" style="display: block; margin: auto;" />
---
## Simple (solo) use of git to prevent merge conflicts
### Before you close a project, always push
<img src="https://hikaruzone.files.wordpress.com/2015/10/in-case-of-fire-1-git-commit-2-git-push-3-leave-building2.png?w=800&h=559" width="80%" style="display: block; margin: auto;" />
---
## Help with Git
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQdltx925phiPYsw72GpjM30TBMn30YLTi8kAlf-N2sC_kTQNTiFQ" width="30%" style="display: block; margin: auto;" />
- [H. Wickham's book](http://r-pkgs.had.co.nz/git.html)
- [Happy Git and GitHub for the useR](http://happygitwithr.com/)
- [Git cheatsheet](https://services.github.com/on-demand/downloads/github-git-cheat-sheet.pdf)
- [When things go wrong](https://github.com/k88hudson/git-flight-rules)
- [To fix a mistake](http://ohshitgit.com/)
- [Create a new branch with git and manage branches](https://github.com/Kunena/Kunena-Forum/wiki/Create-a-new-branch-with-git-and-manage-branches)
---
class: center, middle, inverse
# Demo: RStudio & GitHub
## [Also, video from Nicholas Reich](https://www.youtube.com/watch?v=YxZ8J2rqhEM)
---
## Create a local Git repository
1 - RStudio > New Project > New directory > R packages + create a git repository
2 - Go to the git menu, on the top-right, and add your files of interest:
- (i) save your changes,
- (ii) open the commit window,
- (iii) select files,
- (iv) stage files,
- (v) write a commit message,
- (vi) commit
---
## Create a local Git repository
1 - RStudio > New Project > New directory > R packages + create a git repository
2 - Go to the git menu, on the top-right, and add your files of interest:
3 - Synchronising with GitHub. Go to RStudio > Tools > Shell
- create a new repo on [GitHub](https://github.com/new) and give it the same name as your package
- push your local respository from the command line
`git remote add origin https://github.com/magrichard/testgit.git`
`git push -u origin master`
4 - Check that your GitHub repository is updated [GitHub repo](https://github.com/magrichard/testgit)
---
## Publishing your code on GitHub (or Gitlab...)
1 - Change something (modify the hello.R file and create a new R file)
2 - Go to the git menu, on the top-right, and add your files of interest:
- (i) save your changes,
- (ii) open the commit window,
- (iii) select files,
- (iv) stage files,
- (v) write a commit message,
- (vi) commit
- **(vii) push**
3 - Check that your GitHub repository is updated [GitHub repo](https://github.com/magrichard/testgit)
---
## Import a GitHub repository into RStudio
1 - On GitHub: [create new repo](https://github.com/new) with a README and a description. Leave all the other options as is, then click Submit. (no license, no gitignore...)
2- **CLONE** your repository. **Copy** the web URL
3- In RStudio: Create a New Project > Version Control > Git and **paste** the web URL of the project. Congratulation, you have cloned your new repo.
- => You now have access to Git functionalities within Rstudio
---
## Collaborative work on GitHub
Option 1 - Equal collaborators: Everyone can pull, commit and push on the same 'master' branch
Option 2 - One coordinator (master branch, owns the project) and one (or more) contributor:
![workflow](workflow.png)
---
## Collaborative work on GitHub
Option 1 - Equal collaborators: Everyone can pull, commit and push on the same 'master' branch
Option 2 - One coordinator (master branch, owns the project) and one (or more) contributor:
- Fork the original repo
- Clone it, and link it to the master repo
`git remote add upstream https://github.com/magrichard/testgit.git`
- Uptade your fork with latest changes form the master repo (fetch and merge)
`git pull upstream master`
- Commit, push on your fork, and create a [Pull Request](https://help.github.com/articles/creating-a-pull-request/) (that will be reviewed and accepted by the master)
---
class: center, middle, inverse
# Thanks!
<br>
Presentation available at
https://privefl.github.io/R-presentation/rstudio-git.html
<br>
Twitter: [@privefl](https://twitter.com/privefl) & [@magg_richard](https://twitter.com/magg_richard)
GitHub: [@privefl](https://github.com/privefl) & [@magrichard](https://github.com/magrichard)
.footnote[Slides created via the R package [**xaringan**](https://github.com/yihui/xaringan).]
</textarea>
<script src="https://remarkjs.com/downloads/remark-latest.min.js"></script>
<script>var slideshow = remark.create({
"highlightStyle": "github",
"highlightLines": true,
"countIncrementalSlides": false
});
if (window.HTMLWidgets) slideshow.on('afterShowSlide', function (slide) {window.dispatchEvent(new Event('resize'));});
(function() {var d = document, s = d.createElement("style"), r = d.querySelector(".remark-slide-scaler"); if (!r) return; s.type = "text/css"; s.innerHTML = "@page {size: " + r.style.width + " " + r.style.height +"; }"; d.head.appendChild(s);})();</script>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
skipTags: ['script', 'noscript', 'style', 'textarea', 'pre']
}
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://cdn.bootcss.com/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML';
if (location.protocol !== 'file:' && /^https?:/.test(script.src))
script.src = script.src.replace(/^https?:/, '');
document.getElementsByTagName('head')[0].appendChild(script);
})();
</script>
</body>
</html>