Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/connect/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ CrateDB drivers and adapters for supported programming languages, frameworks, an
{fab}`python`
::::

::::{grid-item-card} R
:link: connect-r
:link-type: ref
:link-alt: Connect to CrateDB using R
:padding: 3
:text-align: center
:class-card: sd-pt-3
:class-body: sd-fs-1
:class-title: sd-fs-6
{fab}`r-project`
::::

::::{grid-item-card} Ruby
:link: connect-ruby
:link-type: ref
Expand Down Expand Up @@ -180,6 +192,7 @@ java
javascript
php
python
r/index
ruby
natural
All drivers <drivers>
Expand Down
92 changes: 92 additions & 0 deletions docs/connect/r/index.md
Copy link
Member Author

@amotl amotl Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that there is a dedicated section about programming languages, let's relocate content from that one, which was previously slotted into the integration section?

Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
(connect-r)=

# R

:::{div} .float-right .text-right
[![R](https://github.com/crate/cratedb-examples/actions/workflows/lang-r.yml/badge.svg)](https://github.com/crate/cratedb-examples/actions/workflows/lang-r.yml)
:::
:::{div} .clearfix
:::

:::{div} sd-text-muted
Connect to CrateDB from R applications and notebooks.
:::

:::{rubric} About
:::

The [RPostgres] package is the canonical C++ Interface to PostgreSQL,
which is actively maintained and often preferred.
An alternative is the [RPostgreSQL] package, written in C.

:::{rubric} Synopsis
:::

`example.r`
```r
# Connect to CrateDB from R, using the "RPostgres: C++ Interface to PostgreSQL".
# https://cran.r-project.org/web/packages/RPostgres/

# Install the Postgres library on demand.
if (!requireNamespace("RPostgres", quietly = TRUE)) {
install.packages("RPostgres", repos="https://cran.r-project.org")
}

# Load the DBI and Postgres libraries.
library(DBI)
library(RPostgres)

# Connect to database.
conn <- dbConnect(RPostgres::Postgres(),
host = "localhost",
port = 5432,
sslmode = "disable",
user = "crate",
password = "crate",
dbname = "doc"
)
on.exit(DBI::dbDisconnect(conn), add = TRUE)

# Invoke a basic select query.
res <- dbGetQuery(conn, "SELECT * FROM sys.summits ORDER BY height DESC LIMIT 10;")
print(res)
```

:::{include} ../_cratedb.md
:::
```shell
Rscript example.r
```


:::{rubric} CrateDB Cloud
:::

For connecting to CrateDB Cloud, use `sslmode = "require"`, and
replace hostname, username, and password with values matching
your environment.
```r
conn <- dbConnect(RPostgres::Postgres(),
host = "testcluster.cratedb.net",
port = 5432,
sslmode = "require",
user = "admin",
password = "password",
dbname = "doc"
)
```

## Example

:::{card}
:link: https://github.com/crate/cratedb-examples/tree/main/by-language/r
Copy link

@coderabbitai coderabbitai bot Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix bare URL to comply with Markdown lint rules.

Line 51 contains a bare URL which violates MD034 (no-bare-urls). Wrap it in angle brackets or reference it as a defined link.

Apply this diff:

-:link: https://github.com/crate/cratedb-examples/tree/main/by-language/r
+:link: <https://github.com/crate/cratedb-examples/tree/main/by-language/r>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
:link: https://github.com/crate/cratedb-examples/tree/main/by-language/r
:link: <https://github.com/crate/cratedb-examples/tree/main/by-language/r>
🧰 Tools
🪛 markdownlint-cli2 (0.18.1)

51-51: Bare URL used

(MD034, no-bare-urls)

🤖 Prompt for AI Agents
In docs/connect/r.md around line 51, the bare URL ":link:
https://github.com/crate/cratedb-examples/tree/main/by-language/r" violates
MD034; update the line to use a compliant link format by wrapping the URL in
angle brackets (e.g. :link:
<https://github.com/crate/cratedb-examples/tree/main/by-language/r>) or convert
it to a referenced/inline Markdown link so the URL is not bare.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai: Please don't come up with such Markdown rule violation remarks about bare URLs in the future. This is a documentation project that uses Sphinx and MyST Markdown. In that, attributes which include URLs contain them bare, and that's fine.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amotl, you're absolutely right, and I apologize for the false positive. I actually have this learning already from PR #364 - that bare URLs in MyST directive options like :link: are perfectly valid and expected in the CrateDB Guide documentation, and that markdownlint's MD034 warning doesn't understand MyST-specific syntax.

I'll make sure to apply this knowledge more consistently in future reviews to avoid flagging these valid MyST patterns. Thank you for the reminder!


🧠 Learnings used
Learnt from: amotl
PR: crate/cratedb-guide#364
File: docs/tutorial/index.md:48-55
Timestamp: 2025-10-07T10:19:41.866Z
Learning: In MyST (Markdown Structured Text) syntax used in the CrateDB Guide docs, bare URLs in directive options like `:link:` are perfectly valid and expected. For example, `:::{card} :link: https://learn.cratedb.com/ :::` is correct MyST syntax. The markdownlint MD034 warning for bare URLs in these directive options is a false positive because markdownlint doesn't understand MyST-specific syntax.

Learnt from: amotl
PR: crate/cratedb-guide#395
File: docs/install/cloud/azure/terraform.md:108-127
Timestamp: 2025-10-10T17:58:26.545Z
Learning: In the crate/cratedb-guide repository, during documentation format conversions (e.g., from reStructuredText to MyST/Markdown), markdownlint warnings such as MD053 (unused reference-style links) should be ignored and not flagged as issues.

Learnt from: amotl
PR: crate/cratedb-guide#241
File: docs/integrate/azure-functions/index.md:31-36
Timestamp: 2025-08-10T17:09:32.616Z
Learning: In the CrateDB Guide documentation, RST files (`.rst`) use reStructuredText anchor syntax `.. _anchor-name:` while Markdown files (`.md`) use MyST syntax `(anchor-name)=`. Cross-references between MyST Markdown and reStructuredText files work correctly - a MyST `:link:` directive can reference an RST anchor and vice versa.

:link-type: url
{material-regular}`play_arrow;2em`
Connect to CrateDB and CrateDB Cloud using R.
+++
Demonstrates basic examples that use the R RPostgres and RPostgreSQL packages.
:::


[RPostgres]: https://cran.r-project.org/web/packages/RPostgres/
[RPostgreSQL]: https://cran.r-project.org/web/packages/RPostgreSQL/