-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07c_evolottery.qmd
263 lines (154 loc) · 7.08 KB
/
07c_evolottery.qmd
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
---
title: "Collaborative coding with GitHub and Rstudio"
subtitle: "EvoLottery"
---
## **EvoLottery**
### **Welcome to the evolutionary lottery of skull and beak morphology**
------------------------------------------------------------------------
<br>
> ##### **Beak and skull shapes in birds of prey (“raptors”) are strongly coupled and largely controlled by size.**
- In this exercise, each participant will **fork a GitHub repo**, and **contribute a file** required to simulate the *evolutionary trajectory of an imaginary species' body size*.
- We'll use **GitHub to collate all species files** and **plot** them all up together at the end! We'll also **discover the skull and beak shapes** associated with each simulated species size.
##### Start!
# Clone Github repo
## Start with GitHub repo
<https://github.com/r-rse/evolottery>
![](assets/repo.png)
## **Fork it**
make your **own copy of the repository** on GitHub. Fork are linked and traceable
![](assets/fork-1.png)
GitHub asks you to confirm some details:
![](assets/fork-1b.png)
And makes a copy in your account:
![](assets/fork-2a-gk.png) You now have a copy in your account!
![](assets/fork-2b-gk.png)
<br>
## **Copy repo URL**
**copy repo link** to create a new Rstudio project from the repository.
![](assets/copy-repo-url.png)
## **Create new project in Posit Cloud from GitHub**
::: {.callout-tip collapse="true"}
## Cloning a repository locally in Rstudio
```{r, echo=FALSE, out.width="90%"}
knitr::include_graphics("assets/newproj-1.png")
```
Checkout from **version control repository**
```{r, echo=FALSE, out.width="90%"}
knitr::include_graphics("assets/newproj-2.png")
```
Clone project from a **git** repository
```{r, echo=FALSE, out.width="90%"}
knitr::include_graphics("assets/newproj-3.png")
```
Paste **repo link copied from GitHub** into **Repository URL** field. Click **`Create Project`**.
```{r, echo=FALSE, out.width="90%"}
knitr::include_graphics("assets/newproj-4.png")
```
Rstudio project now **contains all files from the GitHub repo.**
```{r, echo=FALSE, out.width="90%"}
knitr::include_graphics("assets/newproj-5.png")
```
:::
In your own personal workspace, create a new project from a GitHub repository.
![](assets/pc-proj-from-repo-1.png)
Paste **repo link copied from GitHub** into **Repository URL** field. Click **`Create Project`**.
![](assets/pc-proj-from-repo-2.png) You now have a copy of the materials in you Posit Cloud account, ready to work with!
![](assets/cloned-repo.png)
# **Make a change to the repo**
## Make a copy of `params_tmpl.R`
::: {.alert .alert-warning}
Please ***DO NOT OVERWRITE*** **`params/params_tmpl.R`**.
:::
Click on the **`params/`** folder to open it, select **`params_tmpl.R`** and click on {{< fa cog >}} and **`Copy`**.
![](assets/params-copy-1.png) Use species name of your choice to name new file.
![](assets/params-copy-2.png)
# Edit **new params file**
## Open params file
![](assets/params-open.png) \## Edit params file
Edit file with parameters of your choice and save.
::: {.alert .alert-warning}
Please ***DO NOT OVERWRITE*** **`params/params_tmpl.R`**.
:::
![](assets/params-edit-1.png)
#### The parameters each participants need to supply are:
- **`sig2`:** A numeric value greater than 0 but smaller than 5
- **`species.name`:** a character string e.g. `"anas_krystallinus"`. Try to create a species name out of your name!
- **`color`:** a character string e.g. `"red"`, `"#FFFFFF"` (Check out list of [**colours in R**](http://www.stat.columbia.edu/~tzheng/files/Rcolor.pdf))
**NB: remember to save the changes to your file**
# Commit changes locally to git
In the *git* tab, select the **new file** you created and click **`Commit`**.
::: {.alert .alert-warning}
Please **ONLY COMMIT YOUR NEW FILE**
:::
![](assets/commit-1.png)
Write an informative commit message and click **`Commit`**
![](assets/commit-2.png)
your new file has now been commited
![](assets/commit-3.png)
# Push changes to GitHub
on the *git* tab click ⇧ to **push changes to GitHub**
```{r, echo=FALSE, out.width="90%"}
knitr::include_graphics("assets/push-1.png")
```
![](assets/push-1.png)
changes have now been updated in the **GitHub repo**
```{r, echo=FALSE, out.width="90%"}
knitr::include_graphics("assets/push-2.png")
```
![](assets/push-2.png)
![](assets/push-3.png)
# Create pull request
In your repository, create **`new pull request`** to merge fork to master repo (ie the original repo you forked)
![](assets/pr-1.png)
GitHub checks whether your requested merge creates any coflicts. If all is good, click on **`Create pull request`**
![](assets/pr-2.png)
Write an informative message explaining your changes to the master repo administrators. Click on **`Create pull request`**
![](assets/pr-3.png)
The repository owner will then review your PR and either merge it in or respond with some guidance if they spot a problem.
![](assets/pr-merged-1.png)
Check original repo to see **your merged changes**
![](assets/pr-merged-2.png)
We'll merge all contributions and [plot them together at the end!](https://r-rse.github.io/evolottery/plot_trait_evolution.html)
Now that everyone has contributed to the [**r-rse** repository](https://github.com/r-rse/evolottery) (the **upstream** repository), the `params/` folder contains a number of files, one for each successful pull request.
However your local copy of the repository only contains the template and your own file.
> Q: How can I merge changes from the **upstream** repository to my **local** repository?
## Add upstream remote
### Check current remotes
We can check the urls of remotes currently linked to our local repo using `usethis::git_remotes()`.
``` r
usethis::git_remotes()
```
```
$origin
[1] "https://github.com/annakrystalli/evolottery.git"
```
We see that only my form is currently listed as a remote under the name `origin`.
### Add the r-rse repo as upstream
To add a new remote we need the https url of the upstream repo (the equivalent of the one we used to create our project from our fork through version control) which in this case is `https://github.com/r-rse/evolottery`.
We can then use `usethis::use_git_remote()` to set the upstream repository:
``` r
usethis::use_git_remote(
name = "upstream",
url = "https://github.com/r-rse/evolottery.git")
```
We can check that everything was set correctly with `usethis::git_remotes()`
``` r
usethis::git_remotes()
```
```
$origin
[1] "https://github.com/annakrystalli/evolottery.git"
$upstream
[1] "https://github.com/r-rse/evolottery.git"
```
### Synch with upstream
Finally, to synch with the upstream repository we can now use function `usethis::pr_merge_main()`. This fetches the master branch from the upstream repository and merges it into our own local master branch.
``` r
usethis::pr_merge_main()
```
```
✔ Pulling changes from 'upstream/main'.
```
You should now have all participant files in the `params/` folder and will be able to generate all bird skulls if you run `plot_trait_evolution.Rmd` locally.
## Synch origin
To also synch your origin remote repository you can simply push the merged upstream changes up to GitHub.