⌘K ctrl+k
Search Shortcut cmd + k | ctrl + k

duckdf

duckdf is an SQL interface for R data frames, built on the DuckDB R client. Data frames are registered directly with an in-process DuckDB instance as zero-copy views, queried with standard SQL, and returned as data frame results, without copying data to an external database server. duckdf has no tidyverse dependencies.

Installation

duckdf is available on CRAN and requires duckdb 1.5.6 or later:

install.packages("duckdf")

Querying Data Frames

The duckdf() function runs a SELECT query on the data frames in scope and returns the result as a data frame:

library("duckdf")

df <- data.frame(id = 1:3, value = c(10, 20, 30))
duckdf("SELECT id, value FROM df WHERE value >= 20")
  id value
1  2    20
2  3    30

duckdf finds the data frames referenced in the query using DuckDB's parser, so subqueries, joins, CTEs, and quoted identifiers work. Files that DuckDB reads natively, such as CSV and Parquet files, can be queried without registration.

To skip the table discovery, name the data frame explicitly with the df_name argument. To bind query parameters safely, pass them with the params argument:

duckdf("SELECT mpg, cyl FROM mtcars WHERE disp >= 200", df_name = "mtcars")
duckdf(
  "SELECT mpg FROM mtcars WHERE cyl = $1",
  df = list(mtcars = mtcars),
  params = list(4)
)

Other Functions

Function Description
persist() Run a query on an on-disk DuckDB database, writing the referenced data frames into it as tables
gander() Preview the first five rows of each table in a database
ingest() Read a CSV file into DuckDB, either into a database on disk or returned to R
cleanup() Remove a named on-disk database and close the shared connection
duckdf_views() List the views registered on the shared connection

History

The approach dates from 2020, when issue #459 proposed registering an R data frame as a virtual table with duckdb_register() in duckdb-r. Version 0.2.1 is a rebuild of the package for duckdb 1.5.6 and later.

© 2026 DuckDB Foundation, Amsterdam NL
DuckDB Home Code of Conduct Trademark Use Blog