Nason commited on
Commit
26953c9
·
verified ·
1 Parent(s): cc5d4eb

Add tested R query how-to and correct usage examples

Browse files
Files changed (1) hide show
  1. README.md +17 -0
README.md CHANGED
@@ -52,6 +52,23 @@ FROM ussc.v_sentence_terms GROUP BY 1 ORDER BY 1;
52
  -- indicator (0 = no prison OR under one month); the view separates both.
53
  ```
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  Or with the datapond packages: `pip install datapond` / `pak::pak("datapond-db/datapond-r")`.
56
 
57
  Build pipeline, the USSC codebook and caveats: https://github.com/ian-nason/ussc-database
 
52
  -- indicator (0 = no prison OR under one month); the view separates both.
53
  ```
54
 
55
+ ### R with DBI and duckdb
56
+
57
+ Install the dependencies once with `install.packages(c("DBI", "duckdb"))`.
58
+
59
+ ```r
60
+ library(DBI)
61
+ con <- dbConnect(duckdb::duckdb())
62
+ dbExecute(con, "INSTALL httpfs")
63
+ dbExecute(con, "LOAD httpfs")
64
+ dbExecute(con, "ATTACH 'https://huggingface.co/datasets/Nason/ussc-database/resolve/main/ussc.duckdb' AS ussc (READ_ONLY)")
65
+ dbGetQuery(con, "SELECT fiscal_year FROM ussc.v_sentence_terms LIMIT 5")
66
+ dbDisconnect(con, shutdown = TRUE)
67
+ ```
68
+
69
+ 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.
70
+
71
+
72
  Or with the datapond packages: `pip install datapond` / `pak::pak("datapond-db/datapond-r")`.
73
 
74
  Build pipeline, the USSC codebook and caveats: https://github.com/ian-nason/ussc-database