Skip to content

Commit 2bb1e98

Browse files
committed
updates tos ite
1 parent dc4462d commit 2bb1e98

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+5682
-6875
lines changed

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
content/inClassProblems/week2.Rmd
2+
content/inClassProblems/week3.Rmd
3+
content/inClassProblems/week4.Rmd
4+
content/inClassProblems/week5.Rmd
5+
content/inClassProblems/week6.Rmd
6+
content/inClassProblems/week7.Rmd
7+
content/inClassProblems/week8.Rmd
8+
content/inClassProblems/week9.Rmd
9+
content/inClassProblems/week10.Rmd
10+
content/inClassProblems/week11.Rmd
11+
content/inClassProblems/week12.Rmd
12+
content/inClassProblems/week13.Rmd
13+
content/inClassProblems/week14.Rmd
14+
15+
content/inClassProblems/week2.html
16+
content/inClassProblems/week3.html
17+
content/inClassProblems/week4.html
18+
content/inClassProblems/week5.html
19+
content/inClassProblems/week6.html
20+
content/inClassProblems/week7.html
21+
content/inClassProblems/week8.html
22+
content/inClassProblems/week9.html
23+
content/inClassProblems/week10.html
24+
content/inClassProblems/week11.html
25+
content/inClassProblems/week12.html
26+
content/inClassProblems/week13.html
27+
content/inClassProblems/week14.html

content/code/api.Rmd

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ tadInfo <- jsonlite::fromJSON(content(tad, "text"), simplifyVector = FALSE)
165165

166166

167167

168+
168169
### Class problem:
169170

170171
How long as Tad been on GitHub?
@@ -176,9 +177,16 @@ How long as Tad been on GitHub?
176177
```
177178

178179

180+
That list (`tadInfo`) also has some links to other API calls that could be made. Use the `organizations_url` to get a list of the organizations that Tad is a member of.
181+
182+
183+
```{r class.source = 'fold-hide'}
179184
180185
181186
187+
```
188+
189+
182190

183191

184192

@@ -419,7 +427,7 @@ Now that we know we can connect to the database, let's explore how to get the da
419427

420428
### Querying the database with the SQL syntax
421429

422-
To connect to tables within a database, you can use the `tbl()` function from `dplyr`. This function can be used to send SQL queries to the database. To demonstrate this functionality, lets select the columns "year", "species_id", and "plot_id" from the surveys table:
430+
To connect to tables within a database, you can use the `tbl()` function from `dplyr`. This function can be used to send SQL queries to the database. To demonstrate this functionality, let's select the columns "year", "species_id", and "plot_id" from the surveys table:
423431

424432

425433
```{r}

content/code/git.Rmd

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ output: pdf_document
88

99

1010

11-
12-
13-
14-
1511
## Unix (bash) shell
1612

1713
The best way to directly interact with your computer is through the terminal window. This terminal (in Mac and Linux OSs) is the unix shell, and is commonly referred to as the bash shell, though bash is only one flavor of unix shell (e.g., Ksh shell, fish).
@@ -25,7 +21,7 @@ We will use the bash shell to run some of our programs, and help with makefiles
2521

2622
Open up the terminal.
2723

28-
You should see, at least in Ubuntu, your username followed by a "@" and the name of your machine (e.g., `tad@poe`), followed by ":~$" and a blinking cursor. You are in the home directory by default. To see this, issue the command
24+
You should see, at least in Ubuntu, your username followed by a "@" and the name of your machine (e.g., `tad@tadComputer`), followed by ":~$" and a blinking cursor. You are in the home directory by default. To see this, issue the command
2925

3026
```
3127
pwd
@@ -159,7 +155,7 @@ sudo apt install htop
159155

160156
You also do not strictly need the "-get" part of that. This is a holdover from an earlier version, and I just stuck with it due to muscle memory.
161157

162-
Finally, this should rarely (fingers crossed) be the case when working on these lab computers for people in the course, as I requested that all (hopefully) necessary packages and such be installed prior to you sitting in that seat.
158+
Finally, this should rarely (fingers crossed) be the case when working on these lab computers for people in the course, as I requested that all (hopefully) necessary packages and such be installed prior to you sitting in that seat. For instance, you should have `htop` installed already. You can check on this by typing `htop` into the terminal. What does the output look like?
163159

164160

165161

@@ -195,13 +191,9 @@ Finally, this should rarely (fingers crossed) be the case when working on these
195191
Now we will demonstrate how to use command line utilities. These are things that do not have a GUI (graphical user interface), and therefore must be run through the command line (e.g., nano). The thing we will learn to use through command line is a version control software called `git`.
196192

197193

198-
199-
200-
201194
### What is version control?
202195

203-
Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.
204-
196+
Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.
205197

206198
### Why does it matter?
207199

@@ -210,10 +202,6 @@ Version control is important both for collaborative coding with team members, an
210202

211203

212204

213-
214-
215-
216-
217205
### How do I do it?
218206

219207
I want you to use the folder you made above called `firstRepo` as your first GitHub repo. So navigate to it from command line. Now, initiate the folder as a git repository (i.e., repo).
@@ -293,7 +281,6 @@ To do this, we will navigate to our account on Github, and click the `+` dropdow
293281
git remote add origin https://github.com/userName/repoName.git
294282
```
295283

296-
297284
Now, when we go through the `add, commit, push` process of staging and making a commit (as described above), you will be prompted for your Github username and password.
298285

299286
_you may also need to set some global options of your name and email address when first pushing to Github, but you will be instructed on how exactly to do this_
@@ -307,9 +294,7 @@ Github allows for collaborative coding, meaning that people distributed across t
307294

308295
**What does this mean for you?**
309296

310-
Probably nothing, but it means something for how you will collaborate with your classmates, and how you will turn in assignments. All your dev work for your assignments will be version controlled on Github.
311-
312-
297+
Probably nothing, but it means something for how you will collaborate with your classmates, and how you will turn in assignments. All your dev work for your assignments will be version controlled on Github. On an individual level, especially to graduate researchers in the room, this tool could save you, in the case of poor data backups (how often do you backup your data?), code changes that break functionality (meaning that you probably want to revert), and collaborating with your advisor and others (easier to send a link to a GitHub to demonstrate progress than manuscript drafts called `manuscriptTD_v2_final_final(2).docx`).
313298

314299

315300

content/code/git.html

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,9 @@ <h2>Unix (bash) shell</h2>
370370
<h3>Tutorial</h3>
371371
<p>Open up the terminal.</p>
372372
<p>You should see, at least in Ubuntu, your username followed by a “@”
373-
and the name of your machine (e.g., <code>tad@poe</code>), followed by
374-
“:~$” and a blinking cursor. You are in the home directory by default.
375-
To see this, issue the command</p>
373+
and the name of your machine (e.g., <code>tad@tadComputer</code>),
374+
followed by “:~$” and a blinking cursor. You are in the home directory
375+
by default. To see this, issue the command</p>
376376
<pre><code>pwd</code></pre>
377377
<p>which should output “/home/name”, where “name” is your username
378378
(again, this may be specific to Linux OSs).</p>
@@ -460,7 +460,9 @@ <h2>Downloading programs that you need</h2>
460460
<p>Finally, this should rarely (fingers crossed) be the case when
461461
working on these lab computers for people in the course, as I requested
462462
that all (hopefully) necessary packages and such be installed prior to
463-
you sitting in that seat.</p>
463+
you sitting in that seat. For instance, you should have
464+
<code>htop</code> installed already. You can check on this by typing
465+
<code>htop</code> into the terminal. What does the output look like?</p>
464466
<hr />
465467
</div>
466468
<div id="git" class="section level1">
@@ -569,7 +571,14 @@ <h3>Benefits of Github</h3>
569571
<p><strong>What does this mean for you?</strong></p>
570572
<p>Probably nothing, but it means something for how you will collaborate
571573
with your classmates, and how you will turn in assignments. All your dev
572-
work for your assignments will be version controlled on Github.</p>
574+
work for your assignments will be version controlled on Github. On an
575+
individual level, especially to graduate researchers in the room, this
576+
tool could save you, in the case of poor data backups (how often do you
577+
backup your data?), code changes that break functionality (meaning that
578+
you probably want to revert), and collaborating with your advisor and
579+
others (easier to send a link to a GitHub to demonstrate progress than
580+
manuscript drafts called
581+
<code>manuscriptTD_v2_final_final(2).docx</code>).</p>
573582
</div>
574583
</div>
575584
<div id="so-lets-take-a-tour-of-github" class="section level2">
@@ -602,26 +611,14 @@ <h2>sessionInfo</h2>
602611
## [1] stats graphics grDevices utils datasets methods base
603612
##
604613
## other attached packages:
605-
## [1] tidyr_1.3.1 dplyr_1.1.4 plyr_1.8.9 DBI_1.2.3 geodata_0.5-8
606-
## [6] terra_1.8-50 sf_1.0-21 rgbif_3.7.7 jsonlite_1.8.9 httr_1.4.7
614+
## [1] rmarkdown_2.29
607615
##
608616
## loaded via a namespace (and not attached):
609-
## [1] gtable_0.3.6 xfun_0.49 bslib_0.8.0 ggplot2_3.5.1
610-
## [5] vctrs_0.6.5 tools_4.5.0 generics_0.1.4 curl_6.0.1
611-
## [9] tibble_3.2.1 proxy_0.4-27 RSQLite_2.3.7 blob_1.2.4
612-
## [13] pkgconfig_2.0.3 KernSmooth_2.23-26 data.table_1.16.2 dbplyr_2.5.0
613-
## [17] lifecycle_1.0.4 compiler_4.5.0 stringr_1.5.1 munsell_0.5.1
614-
## [21] codetools_0.2-19 htmltools_0.5.8.1 maps_3.4.1 class_7.3-23
615-
## [25] sass_0.4.9 yaml_2.3.10 lazyeval_0.2.2 pillar_1.10.2
616-
## [29] jquerylib_0.1.4 whisker_0.4.1 classInt_0.4-11 cachem_1.1.0
617-
## [33] tidyselect_1.2.1 digest_0.6.37 stringi_1.8.4 purrr_1.0.2
618-
## [37] fastmap_1.2.0 grid_4.5.0 colorspace_2.1-1 cli_3.6.5
619-
## [41] magrittr_2.0.3 utf8_1.2.5 triebeard_0.4.1 crul_1.5.0
620-
## [45] e1071_1.7-16 withr_3.0.2 scales_1.3.0 bit64_4.5.2
621-
## [49] oai_0.4.0 rmarkdown_2.29 bit_4.5.0 memoise_2.0.1
622-
## [53] evaluate_1.0.1 knitr_1.49 rlang_1.1.6 urltools_1.7.3
623-
## [57] Rcpp_1.0.14 glue_1.8.0 httpcode_0.3.0 xml2_1.3.6
624-
## [61] R6_2.6.1 units_0.8-7</code></pre>
617+
## [1] digest_0.6.37 R6_2.6.1 fastmap_1.2.0 xfun_0.52
618+
## [5] cachem_1.1.0 knitr_1.50 htmltools_0.5.8.1 lifecycle_1.0.4
619+
## [9] cli_3.6.5 sass_0.4.10 jquerylib_0.1.4 compiler_4.5.0
620+
## [13] tools_4.5.0 evaluate_1.0.3 bslib_0.9.0 yaml_2.3.10
621+
## [17] rlang_1.1.6 jsonlite_2.0.0</code></pre>
625622
</div>
626623
</div>
627624

content/code/iteration.Rmd

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,13 @@ tmp3 <- dat |>
129129
130130
```
131131

132-
So summarise expects the output to be a vector (note that there are ways around this, by pulling out the information we want from the cor.test)
133132

134133

135-
```{r}
134+
So `summarise` expects the output to be a vector (note that there are ways around this, by pulling out the information we want from the cor.test)
135+
136+
137+
```{r class.source = 'fold-hide'}
138+
136139
tmp3 <- dat |>
137140
dplyr::group_by(country) |>
138141
dplyr::summarise(cor.test(year, lifeExp)$estimate)
@@ -141,7 +144,7 @@ tmp3 <- dat |>
141144

142145
But how we do pull out multiple values from the same test? And how do we handle and diagnose potential errors when we don't work through each test sequentially?
143146

144-
```{r}
147+
```{r class.source = 'fold-hide'}
145148
146149
lifeExpTime <- matrix(0, ncol=4, nrow=length(countries))
147150
@@ -165,7 +168,7 @@ lifeExpTime$country <- countries
165168

166169
And we can explore these data, to determine which countries have increasing or decreasing life expectancy values as a function of time.
167170

168-
```{r}
171+
```{r class.source = 'fold-hide'}
169172
170173
lifeExpTime[which.min(lifeExpTime$pearsonEst),]
171174
@@ -176,7 +179,9 @@ This may seem like a lot of work when we could have done a bit less using `dplyr
176179

177180
Let's say we want to create a Fibonacci sequence. This is a vector of numbers in which each number is the sum of the two preceding numbers in the vector. For the example, we will limit the length of the vector to be length 1000.
178181

179-
```{r}
182+
183+
184+
```{r class.source = 'fold-hide'}
180185
181186
fib <- c(0,1)
182187
for(i in 3:1000){
@@ -185,10 +190,18 @@ for(i in 3:1000){
185190
186191
```
187192

193+
194+
188195
And now we have a Fibonacci sequence starting with `c(0,1)`.
189196

197+
190198
> Why do I start the `for` loop above at 3, and how else could you approach this same problem (there are many ways)?
191199
200+
```{r class.source = 'fold-hide'}
201+
202+
# You do it.
203+
204+
```
192205

193206

194207

@@ -226,6 +239,7 @@ lapply(X=testList2, FUN=nrow)
226239
227240
```
228241

242+
229243
The output of `lapply` will always be a list, which is nice in some instances and not nice in others. `sapply` is a wrapper for `lapply` which always returns a vector of values.
230244

231245

@@ -275,8 +289,12 @@ sapply(X=testDF, FUN=mean)
275289

276290

277291

292+
293+
294+
278295
## Some practice problems
279296

297+
280298
1. Above, we defined a data set as a list on ringtail diet changes as a function of time. Using those data, calculate the mean dry fragment weight for each of the fragment types.
281299

282300
```{r}
@@ -315,7 +333,8 @@ sapply(X=testDF, FUN=mean)
315333
You are creating a game of rock-paper-scissors. In the game, each player can select their strategy, and the strategy can be different in each trial (where there can be 100s of trials).
316334

317335
I think that the outcome is random, so as a player, I already have decided what I'm going to play before the game starts.
318-
```{r}
336+
337+
```{r class.source = 'fold-hide'}
319338
320339
strat <- sample(c('rock','paper', 'scissors'), 100, replace=TRUE)
321340
@@ -325,15 +344,20 @@ strat <- sample(c('rock','paper', 'scissors'), 100, replace=TRUE)
325344

326345
Write a for loop to simulate rock-paper-scissors game of 500 trials between two players, where my strategy above is one of the players.
327346

328-
```{r}
347+
```{r class.source = 'fold-hide'}
329348
330349
newStrat <- c()
331350
for(i in 1:length(strat)){
332351
newStrat[i] <- sample(c('rock','paper','scissors'),1)
333352
}
334353
335-
# but this is just the same as above. And we need a way to score the result to see who won right? Let's do that now. Write a function that determines who wins each round (so the inputs would be something like x='rock',y='scissors', and it would output `y` or `2` to indicate the winner)
354+
```
355+
356+
336357

358+
But this is just the same as above. And we need a way to score the result to see who won right? Let's do that now. Write a function that determines who wins each round (so the inputs would be something like x='rock',y='scissors', and it would output `y` or `2` to indicate the winner)
359+
360+
```{r class.source = 'fold-hide'}
337361
338362
getScore <- function(x,y){
339363
xScore <- yScore <- c()
@@ -352,10 +376,9 @@ getScore <- function(x,y){
352376

353377

354378

355-
How would you go about changing the strategy of the other player to beat my strategy?
356-
357-
```{r}
379+
How would you go about changing the strategy of the other player to beat my strategy? I'm basically asking you to write code to play the winning move against the opponent when you know the opponent's strategy.
358380

381+
```{r class.source = 'fold-hide'}
359382
360383
tadStrat <- function(opp){
361384
opts <- c('rock', 'paper', 'scissors')
@@ -374,9 +397,9 @@ tadStrat <- function(opp){
374397
return(ret)
375398
}
376399
400+
```
377401

378402

379-
```
380403

381404

382405

@@ -404,7 +427,6 @@ What other way could we approach this problem?
404427

405428
```{r}
406429
407-
408430
# a bit obvious, but I can break down each play and test all 3 strategies, picking the one that works best.
409431
410432
ret <- c()

0 commit comments

Comments
 (0)