You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: hands-on.qmd
+7-22Lines changed: 7 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -187,6 +187,7 @@ species_db %>%
187
187
188
188
Note it means the full query is going to be ran and save in your R environment. This might slow things down, so you generally want to collect on the smallest data frame you can.
189
189
190
+
190
191
#### How can you see the SQL query?
191
192
192
193
Adding `show_query()` at the end of your code block will let you see the SQL code that has been used to query the database.
@@ -210,7 +211,6 @@ Here is how you could run the query using the SQL code directly:
210
211
dbGetQuery(conn, "SELECT Scientific_name FROM Species WHERE (Relevance = 'Study species') ORDER BY Scientific_name LIMIT 3")
211
212
```
212
213
213
-
214
214
You can do pretty much anything with these quasi-tables, including grouping, summarization, joins, etc.
215
215
216
216
Let's count how many species there are per Relevance categories:
@@ -230,26 +230,6 @@ species_db %>%
230
230
show_query()
231
231
```
232
232
233
-
You can also create new columns using mutate:
234
-
235
-
```{r}
236
-
species_db %>%
237
-
mutate(Code = paste("X", Code)) %>%
238
-
head()
239
-
```
240
-
241
-
How does the query looks like?
242
-
243
-
```{r}
244
-
species_db %>%
245
-
mutate(Code = paste("X", Code)) %>%
246
-
head() %>%
247
-
show_query()
248
-
```
249
-
250
-
:::{.callout-caution}
251
-
***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.***
Compute the volume using the same code as previously!!
244
+
Compute the volume using the same code as previously!! Yes, you can use mutate to create new columns on the tables object
265
245
266
246
```{r}
267
247
# Compute the egg volume
268
248
eggs_area_db <- eggs_db %>%
269
249
mutate(egg_volume = pi/6*Width^2*Length)
270
250
```
271
251
252
+
:::{.callout-caution}
253
+
***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.***
254
+
:::
255
+
256
+
272
257
Now let's join this information to the nest table, and average by species
0 commit comments