Working with DuckDB using R’s DBI
The DuckDB R client provides excellent support for the R DBI (https://dbi.r-dbi.org), a standardized API for communicating with DBMS. It’s the standard way of connecting to and querying from databases in R. It is similar in design to the Python DB-API, which we discussed in Chapter 8, with the DBI package aiming to provide a single standardized database interface across the R ecosystem. This enables both R users and R package developers to work with and build against a single interface, rather than having to target a separate API for each target database.
The DBI package contains an extensive range of functions; you can find the complete reference at https://dbi.r-dbi.org/reference. In this section, we’ll cover a subset of the DBI functions that you are likely to find useful for working with DuckDB in R. The core functions that you will want to be comfortable with are as follows:
DBI::dbConnect()
: Create a new connection...