Add tested R query how-to and correct usage examples
Browse files
README.md
CHANGED
|
@@ -46,6 +46,23 @@ SELECT term, decision_direction, COUNT(*) AS n
|
|
| 46 |
FROM scdb.v_cases WHERE term >= 2015 GROUP BY 1, 2 ORDER BY 1, 2;
|
| 47 |
```
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
Or with the datapond packages: `pip install datapond` / `pak::pak("datapond-db/datapond-r")`.
|
| 50 |
|
| 51 |
Build pipeline and caveats: https://github.com/ian-nason/scdb-database
|
|
|
|
| 46 |
FROM scdb.v_cases WHERE term >= 2015 GROUP BY 1, 2 ORDER BY 1, 2;
|
| 47 |
```
|
| 48 |
|
| 49 |
+
### R with DBI and duckdb
|
| 50 |
+
|
| 51 |
+
Install the dependencies once with `install.packages(c("DBI", "duckdb"))`.
|
| 52 |
+
|
| 53 |
+
```r
|
| 54 |
+
library(DBI)
|
| 55 |
+
con <- dbConnect(duckdb::duckdb())
|
| 56 |
+
dbExecute(con, "INSTALL httpfs")
|
| 57 |
+
dbExecute(con, "LOAD httpfs")
|
| 58 |
+
dbExecute(con, "ATTACH 'https://huggingface.co/datasets/Nason/scdb-database/resolve/main/scdb.duckdb' AS scdb (READ_ONLY)")
|
| 59 |
+
dbGetQuery(con, "SELECT term, decision_direction FROM scdb.v_cases LIMIT 5")
|
| 60 |
+
dbDisconnect(con, shutdown = TRUE)
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
DuckDB uses HTTP range requests; queries run on your machine and may need substantial memory or download data. A `LIMIT` does not guarantee a small scan.
|
| 64 |
+
|
| 65 |
+
|
| 66 |
Or with the datapond packages: `pip install datapond` / `pak::pak("datapond-db/datapond-r")`.
|
| 67 |
|
| 68 |
Build pipeline and caveats: https://github.com/ian-nason/scdb-database
|