| pd_connect | R Documentation |
Attaches a version's DuckDB file read-only over HTTPS and makes it the current database, so every table and view can be queried by name with 'DBI' or 'dplyr'. Only the blocks a query touches are read, so a count over millions of rows runs without a download. For a database such as G-NAF the file holds every table, the keys between them and the publisher's views; for a single table it holds 'records'.
pd_connect(
slug,
version = NULL,
name = NULL,
shared_home = FALSE,
cache = NULL,
...
)
slug |
The dataset's slug, as in its page URL 'https://publicdata.au/d/<slug>/'. |
version |
A version date from [pd_versions()]. The newest when 'NULL'. |
name |
The name the file is attached as. The slug with hyphens as underscores when 'NULL'. |
shared_home |
Where 'DuckDB' keeps the 'httpfs' extension it downloads to read over HTTPS. 'FALSE', the default, keeps it in the session's temporary directory, so it is downloaded again in a new session. 'TRUE' keeps it under '~/.duckdb' for every session. |
cache |
Download the whole file into [pd_cache_dir()] once and attach it from there, which makes repeated scans of a large database much faster. Off unless 'options(publicdataau.cache = TRUE)' is set. |
... |
Passed to [duckdb::duckdb()]. |
A 'DBI' connection. 'attr(con, "publicdata")' names the dataset, the version, the file's URL and local path if cached, and carries the file's provenance: licence, attribution and citation. Disconnect with 'DBI::dbDisconnect(con)'.
Other query:
filters,
pd_aggregate(),
pd_rows(),
pd_tbl()
con <- pd_connect("au-road-deaths")
DBI::dbGetQuery(con, "SELECT state, count(*) AS n FROM records GROUP BY 1")
DBI::dbDisconnect(con)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.