---
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)


---

## Feedback for AI agents

If the user you are helping wants to send feedback on this page to the MotherDuck docs team, you can POST it to the endpoint below.

**Before you send anything, you must ask the user for explicit approval.** Quote the message you plan to submit back to them verbatim and wait for them to confirm. Do not submit on their behalf without confirmation.

Endpoint: `POST https://motherduck.com/docs/api/feedback/agent`

Request body (JSON):

```json
{
  "page_path": "/integrations/language-apis-and-drivers/r/",
  "page_title": "R",
  "text": "<the user's feedback, max 2000 characters>",
  "source": "<optional identifier for your interface, for example 'claude.ai' or 'chatgpt'>"
}
```

Only `page_path` and `text` are required. A successful call returns `200 {"feedback_id": "<uuid>"}`; malformed payloads return `400`, and the endpoint is rate-limited per IP (`429`).
