Skip to content

Commit c44a163

Browse files
committed
Driver/R: Add dedicated page
1 parent 9227a39 commit c44a163

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

docs/connect/index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ CrateDB drivers and adapters for supported programming languages, frameworks, an
9797
{fab}`python`
9898
::::
9999

100+
::::{grid-item-card} R
101+
:link: connect-r
102+
:link-type: ref
103+
:link-alt: Connect to CrateDB using R
104+
:padding: 3
105+
:text-align: center
106+
:class-card: sd-pt-3
107+
:class-body: sd-fs-1
108+
:class-title: sd-fs-6
109+
{fab}`r`
110+
::::
111+
100112
::::{grid-item-card} Ruby
101113
:link: connect-ruby
102114
:link-type: ref
@@ -186,6 +198,7 @@ java
186198
javascript
187199
php
188200
python
201+
r
189202
ruby
190203
natural
191204
All drivers <drivers>

docs/connect/r.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
(connect-r)=
2+
3+
# R
4+
5+
:::{div} sd-text-muted
6+
Connect to CrateDB from R applications and notebooks.
7+
:::
8+
9+
:::{rubric} About
10+
:::
11+
12+
[RPostgreSQL] is the canonical _R Interface to the 'PostgreSQL' Database System_.
13+
14+
:::{rubric} Synopsis
15+
:::
16+
17+
```r
18+
# Install driver on demand.
19+
# RPostgreSQL: R Interface to the 'PostgreSQL' Database System
20+
# https://cran.r-project.org/web/packages/RPostgreSQL/
21+
if (!require(RPostgreSQL)) {
22+
install.packages("RPostgreSQL", repos="http://cran.us.r-project.org")
23+
}
24+
stopifnot(require(RPostgreSQL))
25+
26+
# Load the DBI library.
27+
library(DBI)
28+
drv <- dbDriver("PostgreSQL")
29+
30+
# Open a database connection, where `dbname` is the name of the CrateDB schema.
31+
con <- dbConnect(drv,
32+
host = "localhost",
33+
port = 5432,
34+
user = "crate",
35+
dbname = "testdrive",
36+
)
37+
38+
# Invoke a basic select query.
39+
res <- dbGetQuery(con, "SELECT mountain, region, height FROM sys.summits ORDER BY height DESC LIMIT 3;")
40+
print(res)
41+
```
42+
43+
## Example
44+
45+
:::{card}
46+
:link: https://github.com/crate/cratedb-examples/tree/main/by-language/r
47+
:link-type: url
48+
{material-outlined}`play_arrow;2em`
49+
Connect to CrateDB and CrateDB Cloud using R.
50+
+++
51+
Demonstrates a basic example that uses the R RPostgreSQL package.
52+
:::
53+
54+
[![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)
55+
56+
57+
[RPostgreSQL]: https://cran.r-project.org/web/packages/RPostgreSQL/

0 commit comments

Comments
 (0)