backend-duckdb {duckdb}R Documentation

DuckDB SQL backend for dbplyr

Description

This is a SQL backend for dbplyr tailored to take into account DuckDB's possibilities. This mainly follows the backend for PostgreSQL, but contains more mapped functions.

tbl_file() is an experimental variant of dplyr::tbl() to directly access files on disk. It is safer than dplyr::tbl() because there is no risk of misinterpreting the request, and paths with special characters are supported.

tbl_query() is an experimental variant of dplyr::tbl() to create a lazy table from a table-generating function, useful for reading nonstandard CSV files or other data sources. It is safer than dplyr::tbl() because there is no risk of misinterpreting the query. Use dplyr::tbl(src, dplyr::sql("SELECT ... FROM ...")) for custom SQL queries. See https://duckdb.org/docs/data/overview for details on data importing functions.

Usage

simulate_duckdb(...)

translate_duckdb(...)

tbl_file(src, path, ..., cache = FALSE)

tbl_query(src, query, ..., cache = FALSE)

Arguments

...

Any parameters to be forwarded

src

A duckdb connection object

path

Path to existing Parquet, CSV or JSON file

cache

Enable object cache for Parquet files

query

SQL code, omitting the FROM clause

Examples


library(dplyr, warn.conflicts = FALSE)
con <- DBI::dbConnect(duckdb(), path = ":memory:")

dbiris <- copy_to(con, iris, overwrite = TRUE)

dbiris %>%
  select(Petal.Length, Petal.Width) %>%
  filter(Petal.Length > 1.5) %>%
  head(5)

DBI::dbDisconnect(con, shutdown = TRUE)


[Package duckdb version 0.10.1 Index]