R
R is a language for statistical analysis.
To connect to MotherDuck from an R program, you need to first install DuckDB:
install.packages("duckdb")
You'll then need to load the motherduck
extension and ATTACH 'md:'
to connect to all of your databases.
To connect to only one database, use ATTACH 'md:my_db'
syntax.
library("DBI")
con <- dbConnect(duckdb::duckdb())
dbExecute(con, "LOAD 'motherduck'")
dbExecute(con, "ATTACH 'md:'")
dbExecute(con, "USE my_db")
res <- dbGetQuery(con, "SHOW DATABASES")
print(res)
Once connected, any R syntax described in the DuckDB's documentation should work.
note
Extension autoloading is turned off in R duckdb distributions, so dbdir = "md:"
style connections do not connect to MotherDuck.
Considerations and limitations
Windows integration
MotherDuck extension is not currently available on Windows. As a workaround, you can use WSL (Windows Subsystem for Linux)