@@ -16,27 +16,28 @@ RPostgres is actively maintained and often preferred.
1616:::{rubric} Synopsis
1717:::
1818
19+ ` example.r `
1920``` r
20- # RPostgres: C++ Interface to PostgreSQL
21+ # Connect to CrateDB from R, using the " RPostgres: C++ Interface to PostgreSQL".
2122# https://cran.r-project.org/web/packages/RPostgres/
2223
23- # Optionally install the PostgreSQL library on demand.
24+ # Install the Postgres library on demand.
2425if (! requireNamespace(" RPostgres" , quietly = TRUE )) {
2526 install.packages(" RPostgres" , repos = " https://cran.r-project.org" )
2627}
2728
28- # Load the DBI and PostgreSQL libraries.
29+ # Load the DBI and Postgres libraries.
2930library(DBI )
3031library(RPostgres )
3132
32- # Open a database connection, where `dbname` is the name of the CrateDB schema .
33+ # Connect to database.
3334conn <- dbConnect(RPostgres :: Postgres(),
3435 host = " localhost" ,
3536 port = 5432 ,
3637 sslmode = " disable" ,
3738 user = " crate" ,
3839 password = " crate" ,
39- dbname = " testdrive " ,
40+ dbname = " doc "
4041 )
4142on.exit(DBI :: dbDisconnect(conn ), add = TRUE )
4243
@@ -45,13 +46,32 @@ res <- dbGetQuery(conn, "SELECT * FROM sys.summits ORDER BY height DESC LIMIT 10
4546print(res )
4647```
4748
48- :::{note}
49- ** ⚠️ Security note:** The example uses hardcoded credentials and disables SSL
50- for simplicity. In production, use environment variables or secrets management
51- (e.g., ` .Renviron ` , keyvault) and enable TLS verification
52- (` sslmode="verify-full" ` or ` "require" ` ).
49+ Start CrateDB using Docker or Podman, then invoke the example program.
50+ ``` shell
51+ docker run --rm --publish=5432:5432 crate -Cdiscovery.type=single-node
52+ ```
53+ ``` shell
54+ Rscript example.r
55+ ```
56+
57+
58+ :::{rubric} CrateDB Cloud
5359:::
5460
61+ For connecting to CrateDB Cloud, use ` sslmode = "require" ` , and
62+ replace username, password, and hostname with values matching
63+ your environment.
64+ ``` r
65+ conn <- dbConnect(RPostgres :: Postgres(),
66+ host = " testcluster.cratedb.net" ,
67+ port = 5432 ,
68+ sslmode = " require" ,
69+ user = " admin" ,
70+ password = " password" ,
71+ dbname = " doc"
72+ )
73+ ```
74+
5575## Example
5676
5777:::{card}
0 commit comments