API Libraries > Rlang

Rlang

This document describes how to use R language client (RRockset). R client is a DBI-based adapter for Rockset and supports only read operations (querying collections).

The R client library code is available here.

Installation

Install devtools package in order to install RRockset:

install.packages('devtools')
library('devtools')

You can now install the R client using:

devtools::install_github('rockset/RRockset@v0.1.0')

Connect

In order to use RRockset, you will need a valid Rockset API key. You can create an API Key using the Rockset Console under Manage > API Keys.

Rockset API Keys

Usage

Query

Simple query:

library('DBI')
sql <- "select _id, kind from _events limit 5"
con <- dbConnect(RRockset::Rockset(), apikey='<api-key>')

# fetch the documents using dbSendQuery
res <- dbSendQuery(con, sql)
print(dbFetch(res))

# use dbGetQuery
res <- dbGetQuery(con, sql)
print(res)

Using parameters:

library('DBI')
sql <- "select _id, kind from _events where kind = :kind limit 5"
param1 <- list(name = "kind", type = "string", value = "ORGANIZATION")
params <- list(param1)
con <- dbConnect(RRockset::Rockset(), apikey='<api-key>')

# fetch the documents
res <- dbSendQuery(con, sql, params)
print(dbFetch(res))

Fetch one chunk at a time:

library('DBI')
sql <- "select * from _events"
con <- dbConnect(RRockset::Rockset(), apikey='<api-key>')
res <- dbSendQuery(con, sql)
while(!dbHasCompleted(res)) {
  # fetch 10 documents at a time
  print(dbFetch(res, n = 10)) 
}

# clear the result
dbClearResult(res)