Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.

Commit

Permalink
Complete technical prep
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiddelkoop committed May 22, 2024
1 parent e4da6bb commit a2aae13
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*.html
Test.*
data/
data_raw/
4 changes: 3 additions & 1 deletion prep/Preparation-RNotebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
"library(tidyverse)\n",
"library(lubridate)\n",
"library(ratdat)\n",
"library(ggplot2)"
"library(ggplot2)\n",
"\n",
"install.packages(c(\"dbplyr\", \"RSQLite\"))"
]
},
{
Expand Down
29 changes: 29 additions & 0 deletions prep/Preparation-RStudio.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,32 @@ Write Data
```{r}
write_csv(surveys, "data/cleaned/test.csv")
```

## Databases

Setup
```{r}
dir.create('data_raw', recursive = TRUE, showWarnings = FALSE)
install.packages(c("dbplyr", "RSQLite"))
library(dplyr)
library(dbplyr)
```

Download and connect to database
```{r}
download.file(url = "https://ndownloader.figshare.com/files/2292171",
destfile = "data_raw/portal_mammals.sqlite", mode = "wb")
mammals <- DBI::dbConnect(RSQLite::SQLite(), "data_raw/portal_mammals.sqlite")
src_dbi(mammals)
```

Run Queries
```{r}
tbl(mammals, sql("SELECT year, species_id, plot_id FROM surveys"))
surveys <- tbl(mammals, "surveys")
surveys %>%
select(year, species_id, plot_id)
head(surveys, n = 10)
```
5 changes: 5 additions & 0 deletions prep/Setup.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ Packages from Lesson 1
```{r message=FALSE, warning=FALSE}
install.packages("ggplot2")
```

Packages from Data Lesson
```{r message=FALSE, warning=FALSE}
install.packages(c("dbplyr", "RSQLite"))
```

0 comments on commit a2aae13

Please sign in to comment.