Skip to content

Commit 9a453d2

Browse files
committed
improve readability
1 parent fafd872 commit 9a453d2

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

hands-on.qmd

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ species_study <- species_csv %>%
6464
species_study
6565
```
6666

67-
#### Average egg volume
67+
### Average egg volume
6868

69+
:::{.callout-tip}
70+
## Analysis
6971
We would like to know what is the average egg size for each of those bird species. How would we do that?
72+
:::
7073

7174
We will need more information that what we have in our species table. Actually we will need to also retrieve information from the nests and eggs monitoring table.
7275

@@ -147,7 +150,7 @@ List all the tables present in the database:
147150
dbListTables(conn)
148151
```
149152

150-
### Let's try to reproduce the analaysis we just did
153+
Let's have a look at the Species table
151154

152155
```{r}
153156
species_db <- tbl(conn, "Species")
@@ -233,13 +236,13 @@ species_db %>%
233236
head() %>%
234237
show_query()
235238
```
236-
:::warning
239+
:::{.callout-caution}
237240
Limitation: no way to add or update data in the database, `dbplyr` is view only. If you want to add or update data, you'll need to use the `DBI` package functions.
238241
:::
239242

240-
#### Average egg volume
243+
### Average egg volume analysis
241244

242-
Calculating the average bird eggs volume per species directly on the database
245+
Let's reproduce the egg volume analysis we just did. We can calculate the average bird eggs volume per species directly on the database
243246

244247
```{r}
245248
# loading all the necessary tables
@@ -250,13 +253,15 @@ nests_db <- tbl(conn, "Bird_nests")
250253
Compute the volume:
251254

252255
```{r}
256+
# Compute the egg volume
253257
eggs_area_db <- eggs_db %>%
254258
mutate(egg_volume = pi/6*Width^2*Length)
255259
```
256260

257261
Now let's join this information to the nest table, and average by species
258262

259263
```{r}
264+
# Join the egg and nest tables to compute average
260265
species_egg_volume_avg_db <- left_join(nests_db, eggs_area_db, by="Nest_ID") %>%
261266
group_by(Species) %>%
262267
summarise(egg_volume_avg = mean(egg_volume, na.rm = TRUE)) %>%
@@ -267,6 +272,8 @@ species_egg_volume_avg_db <- left_join(nests_db, eggs_area_db, by="Nest_ID") %>%
267272
species_egg_volume_avg_db
268273
```
269274

275+
What does this SQL quert looks like?
276+
270277
```{r}
271278
species_egg_volume_avg_db <- left_join(nests_db, eggs_area_db, by="Nest_ID") %>%
272279
group_by(Species) %>%
@@ -275,7 +282,8 @@ species_egg_volume_avg_db <- left_join(nests_db, eggs_area_db, by="Nest_ID") %>%
275282
show_query()
276283
```
277284

278-
:::note
285+
:::{.callout-note}
286+
## Question
279287
Why does the SQL query include the volume computation?
280288
:::
281289

0 commit comments

Comments
 (0)