Skip to content
Storage

R Client Library

The R client library is a Storage API client which you can use in your R code. The current implementation supports all basic data manipulations:

  • Importing data
  • Exporting data
  • Creating and deleting buckets and tables

The client source code is available in our Github repository.

This library is available on Github, so we recommend that you use the devtools package to install it.

# first install the devtools package if it isn't already installed
install.packages("devtools")
# install dependencies (another github package for aws requests)
devtools::install_github("cloudyr/aws.s3")
# install the SAPI R client package
devtools::install_github("keboola/sapi-r-client")
# load the library (dependencies will be loaded automatically)
library(keboola.sapi.r.client)

To list available commands, run

?keboola.sapi.r.client::SapiClient

The client is implemented as an RC class. To work with it, create an instance of the client. It requires a valid Storage API token and your stack’s Storage API URL (https://connection.keboola.com on AWS US; use your stack’s endpoint otherwise).

client <- SapiClient$new(
token = 'your-token',
url = 'https://connection.keboola.com'
)

Example --- Create a Table and Import Data

Section titled “Example --- Create a Table and Import Data”

To create a new table in Storage, use the saveTable function. Provide the name of an existing bucket, the name of the new table and a CSV file with the table’s contents.

To create the new-table table in the in.c-main bucket, use

myDataFrame <- data.frame(id = c(1,2,3,4), secondCol = c('a', 'b', 'c', 'd'))
client <- SapiClient$new(
token = 'your-token',
url = 'https://connection.keboola.com'
)
table <- client$saveTable(
df = myDataFrame,
bucket = "in.c-main",
tableName = "new-table",
options = list(primaryKey = 'id')
)

The above command will import the contents of the myDataFrame variable into the newly created table. It will also mark the id column as the primary key.

If you want to export a table from Storage and import it into R, use the importTable function. Provide the ID (bucketName.tableName) of an existing table.

To export data from the old-table table in the in.c-main bucket, use

client <- SapiClient$new(
token = 'your-token',
url = 'https://connection.keboola.com'
)
data <- client$importTable('in.c-main.old-table')

The above command will export the table from Storage and save it in the data variable. The output is a data.table object compatible with a data.frame.

# create a client
client <- SapiClient$new(
token = 'your-token',
url = 'https://connection.keboola.com'
)
# verify the token
tokenDetails <- client$verifyToken()
# create a bucket
bucket <- client$createBucket("new_bucket", "in", "A brand new Bucket!")
# list buckets
buckets <- client$listBuckets()
# list all tables
tables <- client$listTables()
# list all tables in a bucket
tables <- client$listTables(bucket = bucket$id)
# delete a table
client$deleteTable(table$id)
# delete a bucket
client$deleteBucket(bucket$id)
Ask Kai

Hi, I'm Kai — Keboola's AI assistant for the docs. Ask me anything and I'll answer from the documentation and cite the pages I use.

Kai is an AI and can make mistakes. Check the sources it links.