pd_connect: Connect to a version with DuckDB

View source: R/publicdataau.R

pd_connectR Documentation

Connect to a version with DuckDB

Description

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'.

Usage

pd_connect(
  slug,
  version = NULL,
  name = NULL,
  shared_home = FALSE,
  cache = NULL,
  ...
)

Arguments

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()].

Value

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)'.

See Also

Other query: filters, pd_aggregate(), pd_rows(), pd_tbl()

Examples


con <- pd_connect("au-road-deaths")
DBI::dbGetQuery(con, "SELECT state, count(*) AS n FROM records GROUP BY 1")
DBI::dbDisconnect(con)


publicdataau documentation built on Oct. 14, 2026, 5:07 p.m.