-
Notifications
You must be signed in to change notification settings - 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?
Conversation
Warning Rate limit exceeded@amotl has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 45 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
WalkthroughAdds R support to the Connect docs: inserts an R driver card into the Drivers-by-language grid in Changes
Sequence Diagram(s)Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
b5dd4a8
to
afad979
Compare
docs/connect/r.md
Outdated
```r | ||
# Install driver on demand. | ||
# RPostgreSQL: R Interface to the 'PostgreSQL' Database System | ||
# https://cran.r-project.org/web/packages/RPostgreSQL/ | ||
|
||
# Optionally install the PostgreSQL library. | ||
if (!requireNamespace("RPostgreSQL", quietly = TRUE)) { | ||
install.packages("RPostgreSQL", repos="https://cran.r-project.org") | ||
} | ||
|
||
# Load the DBI and PostgreSQL libraries. | ||
library(DBI) | ||
library(RPostgreSQL) | ||
drv <- RPostgreSQL::PostgreSQL() |
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.
@coderabbitai suggested:
17-31
: Optional: mention RPostgres as the modern alternative.RPostgres (PostgreSQL DBI driver) is actively maintained and often preferred; it also works with the PG wire protocol.
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.
Indeed, two driver variants exist. Let's re-evaluate which one to present, or otherwise present both separately.
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.
🧩 Analysis chain
🌐 Web query:
RPostgres vs RPostgreSQL comparison 2024 2025 which is better actively maintained
💡 Result:
Short answer: RPostgres is the more actively maintained and recommended driver in 2024–2025 (modern C++ backend, DBI‑feature support); RPostgreSQL still exists and receives occasional updates but is older and less featureful. [1][2][3]
Quick evidence
- RPostgres: actively maintained, CRAN/dev releases in 2024–2025, maintained by Kirill Müller and r-dbi with GitHub/CRAN activity and documentation. [1][4][5]
- RPostgreSQL: older, C-backed driver with its last CRAN release notes in 2024 (and occasional 2025 packaging updates), but it is not the modern DBI implementation and lacks some features (e.g. full parameterized-query support) found in RPostgres. [6][2]
Recommendation
- Use RPostgres for new projects (better performance, parameterised queries, automatic cleanup, active r-dbi maintenance). Use RPostgreSQL only if you have legacy code that depends on it. [1][4][6]
Sources
- RPostgres project page / r-dbi documentation (features, design, maintainer). [rpostgres.r-dbi.org].
- CRAN package page / CRAN-e listing for RPostgres (recent releases/versions).
- CRAN checks and r-universe/manual pages showing 2024–2025 builds and versions.
- RPostgres GitHub / r-dbi (source/docs/activity).
- RPostgreSQL CRAN/CRAN-e package page and release history (last upstream releases in 2024; occasional packaging updates in 2025).
If you want I can list the exact CRAN/GitHub release dates and links (with numbered citations).
🌐 Web query:
RPostgreSQL maintenance status CRAN last update
💡 Result:
RPostgreSQL is currently maintained; the latest CRAN release is version 0.7-8 (released March 28, 2025). Maintainer: Tomoaki Nishiyama. [1][2]
Sources:
- CRAN update notice (RPostgreSQL 0.7-8, 2025-03-28). [1]
- Package reference/manual (version 0.7-8; built 2025-07-29). [2]
🌐 Web query:
RPostgres modern R PostgreSQL driver best practices
💡 Result:
Quick best-practices for using RPostgres (concise):
- Use the DBI + RPostgres API (DBI::dbConnect(RPostgres::Postgres())) and prefer RPostgres over RPostgreSQL (modern C++ backend, safer cleanup). (rpostgres.r-dbi.org)
- Use parameterized queries / prepared statements (dbSendQuery() + dbBind() or dbExecute()/params) to prevent SQL injection and reuse plans. (dbi.r-dbi.org)
- Manage transactions explicitly when needed: DBI::dbBegin()/dbCommit()/dbRollback() (or savepoints) to ensure atomicity. Use on.exit()/withr::defer() to always close/rollback on error. (rpostgres.r-dbi.org)
- Use a connection pool (pool::dbPool) in long‑running apps (Shiny, Plumber) rather than opening ad‑hoc connections; tune minSize/maxSize and idleTimeout and always poolClose() on shutdown. (rstudio.github.io)
- Fetch large results in chunks: dbSendQuery() → dbFetch(n) → dbClearResult() to avoid OOM. Use dbGetQuery() only if result fits memory. (r-dbi.r-universe.dev)
- Bulk writes: prefer DBI::dbWriteTable(..., copy = TRUE) or COPY-based approaches for large data loads (use server-side COPY where supported). Validate types (bigint → integer64) and cast params if needed (e.g. "$1::bigint"). (r-dbi.r-universe.dev)
- Enforce TLS/SSL and least-privilege DB credentials for production; supply host/sslmode and use managed secrets (env vars, keyvault) rather than hardcoding. (rpostgres.r-dbi.org)
- Clean up: always dbClearResult(), dbDisconnect() (or poolClose()); use on.exit() / withr::defer() to avoid leaks. RPostgres auto-cleans more than older drivers but explicit cleanup is still best practice. (rpostgres.r-dbi.org)
- Monitor & right-size: monitor active connections on Postgres side, set pool max below DB max_connections, add retry/backoff for transient failures. (compilenrun.com)
- Use dbplyr for pushdown where appropriate (let the DB do filtering/aggregation); ensure proper indexing and examine query plans for hotspots. (rstudio.github.io)
If you want, I can produce copy‑pasteable example snippets for: (a) secure dbPool usage, (b) parameterized dbBind pattern, or (c) a safe transaction pattern. Which one first?
Citations:
- 1: https://rpostgres.r-dbi.org/?utm_source=openai
- 2: https://dbi.r-dbi.org/reference/dbBind.html?utm_source=openai
- 3: https://rpostgres.r-dbi.org/reference/postgres-transactions.html?utm_source=openai
- 4: https://rstudio.github.io/pool/reference/dbPool.html?utm_source=openai
- 5: https://r-dbi.r-universe.dev/RPostgres/doc/manual.html?utm_source=openai
- 6: https://r-dbi.r-universe.dev/RPostgres/doc/manual.html?utm_source=openai
- 7: https://rpostgres.r-dbi.org/?utm_source=openai
- 8: https://rpostgres.r-dbi.org/?utm_source=openai
- 9: https://www.compilenrun.com/docs/database/postgresql/postgresql-best-practices/postgresql-connection-pooling/?utm_source=openai
- 10: https://rstudio.github.io/pool/reference/tbl.Pool.html?utm_source=openai
@amotl, based on current information, here's my recommendation:
Key Differences
RPostgres (recommended):
- Modern, actively maintained by the r-dbi team
- C++ backend with better performance
- Full DBI feature support including parameterized queries
- Automatic connection cleanup
- Preferred for new projects in 2024-2025
RPostgreSQL:
- Older C-backed driver
- Still maintained (v0.7-8 released March 2025)
- Less featureful than RPostgres
- Typically only used for legacy code compatibility
Recommendation
I suggest switching to RPostgres as the primary driver in your documentation since:
- This is new documentation (not maintaining legacy code)
- RPostgres is the community-recommended modern approach
- Both work with the PostgreSQL wire protocol, so both should work with CrateDB
You could optionally add a brief note mentioning RPostgreSQL as an alternative for users with existing code, but keeping the main example with RPostgres would be clearer and more helpful.
Would you like me to help update the code example to use RPostgres instead? The changes would be minimal:
# Install RPostgres instead
if (!requireNamespace("RPostgres", quietly = TRUE)) {
install.packages("RPostgres", repos="https://cran.r-project.org")
}
library(DBI)
library(RPostgres)
# No need to create drv object - use RPostgres::Postgres() directly in dbConnect()
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.
@coderabbitai: Switched per cdbcf93.
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.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check the commit referenced by the user
git show cdbcf938561 --stat
echo "---"
# Show the actual changes in the R documentation file
git show cdbcf938561 -- docs/connect/r.md
Length of output: 3373
@amotl Perfect! The changes look excellent. You've successfully switched to RPostgres as the primary driver while thoughtfully keeping RPostgreSQL mentioned as an alternative.
The implementation is clean and follows best practices:
- ✅ Uses
RPostgres::Postgres()
directly indbConnect()
(no need for the intermediatedrv
object) - ✅ Clear explanation that RPostgres is actively maintained and preferred
- ✅ Still mentions RPostgreSQL for users who might need it
- ✅ Updated all references, comments, and examples consistently
The documentation now provides modern, recommended guidance for R users connecting to CrateDB. Great work!
♪┏(・o・)┛♪┗ ( ・o・) ┓♪
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.
@coderabbitai: Thank you for pointing out RPostgres, so we have been able to improve our docs. 💯
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.
@amotl You're very welcome! I'm glad the suggestion was helpful. The documentation now reflects the modern best practices for R users, which will benefit the community. Happy to assist anytime! 🚀
3ace5ab
to
cdbcf93
Compare
2756c81
to
08b6054
Compare
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 slotted into the integration section instead.
About
What the title says.
Preview
https://cratedb-guide--405.org.readthedocs.build/connect/r/