I'm working with the slidify package to build a presentation and I am trying to incorporate the RSQLite package. On the first slide, where the connection is made, all of the code works fine. However, on the second slide it's telling me that the connection has expired and dbIsValid( ) returns False when I check it in R.
I'm not entirely sure how to ask my question because I'm not entirely sure why the connection is terminating itself and I don't know a lot about SQL.
The code I'm using for the slides is below.
## Working with Data - SQL
```{r}
library(RSQLite)
con <- dbConnect(SQLite(), '')
dbWriteTable(con, 'Arrests', datasets::USArrests)
dbListTables(con)
dbGetQuery(con, 'SELECT * FROM Arrests LIMIT 3')
```
---
```{r}
dbGetQuery(con, 'SELECT * FROM Arrests WHERE row_names LIKE "A%"')
dbGetQuery(con, 'CREATE TABLE Totals AS SELECT DISTINCT
row_names, Murder + Rape + Assault as Total FROM Arrests')
dbGetQuery(con, 'SELECT * FROM Totals LIMIT 3')
```
The first part is pulled directly from the RSQLite documentation and works fine. The second part gives me the aforementioned error. Why is the connection expiring despite no call to dbDisconnect(con) being made?
As always, thanks for the help!
Aucun commentaire:
Enregistrer un commentaire