---
sidebar_position: 1
title: R
description: Connect to MotherDuck from R for statistical analysis using the DuckDB R package.
---

[R](https://www.r-project.org/) is a language for statistical analysis.

To connect to MotherDuck from an R program, you need to first install DuckDB:

```r
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.

```r
library("DBI")
con <- dbConnect(duckdb::duckdb())
dbExecute(con, "INSTALL 'motherduck'")
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](https://duckdb.org/docs/api/r.html) 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](https://learn.microsoft.com/en-us/windows/wsl/about) (Windows Subsystem for Linux)
