-
Couldn't load subscription status.
- Fork 1
Driver: Add page about R #405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,92 @@ | ||||||
| (connect-r)= | ||||||
|
|
||||||
| # R | ||||||
|
|
||||||
| :::{div} .float-right .text-right | ||||||
| [](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 | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Suggested change
🧰 Tools🪛 markdownlint-cli2 (0.18.1)51-51: Bare URL used (MD034, no-bare-urls) 🤖 Prompt for AI AgentsThere was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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 |
||||||
| :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/ | ||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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?