Skip to content

Commit e284607

Browse files
committed
Driver/R: Implement suggestions by CodeRabbit
1 parent c44a163 commit e284607

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

docs/connect/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ CrateDB drivers and adapters for supported programming languages, frameworks, an
106106
:class-card: sd-pt-3
107107
:class-body: sd-fs-1
108108
:class-title: sd-fs-6
109-
{fab}`r`
109+
{fab}`r-project`
110110
::::
111111

112112
::::{grid-item-card} Ruby

docs/connect/r.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,28 @@ Connect to CrateDB from R applications and notebooks.
1818
# Install driver on demand.
1919
# RPostgreSQL: R Interface to the 'PostgreSQL' Database System
2020
# https://cran.r-project.org/web/packages/RPostgreSQL/
21-
if (!require(RPostgreSQL)) {
22-
install.packages("RPostgreSQL", repos="http://cran.us.r-project.org")
21+
22+
# Optionally install the PostgreSQL library.
23+
if (!requireNamespace("RPostgreSQL", quietly = TRUE)) {
24+
install.packages("RPostgreSQL", repos="https://cran.r-project.org")
2325
}
24-
stopifnot(require(RPostgreSQL))
2526

26-
# Load the DBI library.
27+
# Load the DBI and PostgreSQL libraries.
2728
library(DBI)
28-
drv <- dbDriver("PostgreSQL")
29+
library(RPostgreSQL)
30+
drv <- RPostgreSQL::PostgreSQL()
2931

3032
# Open a database connection, where `dbname` is the name of the CrateDB schema.
3133
con <- dbConnect(drv,
3234
host = "localhost",
3335
port = 5432,
36+
# For CrateDB Cloud:
37+
# sslmode = "require",
3438
user = "crate",
35-
dbname = "testdrive",
39+
password = Sys.getenv("CRATEDB_PASSWORD"),
40+
dbname = "testdrive"
3641
)
42+
on.exit(DBI::dbDisconnect(con), add = TRUE)
3743

3844
# Invoke a basic select query.
3945
res <- dbGetQuery(con, "SELECT mountain, region, height FROM sys.summits ORDER BY height DESC LIMIT 3;")

0 commit comments

Comments
 (0)