delika R Client

Preview: This feature in preview state and might change or have limited support.

Package Name

delika

Requirements

  • caTools
  • httr
  • jsonlite
  • R6

Installation

Almost users install the latest version of delika package in the following code:

# choose your favorite CRAN instead of https://cloud.r-project.org
repos <- c("https://cloud.r-project.org", "https://docs.delika.io/R")

# install the package and its dependencies.
install.packages("delika", repos = repos)

If you need to install a specific version of the package, you can do in the following code:

repos <- c("https://cloud.r-project.org", "https://docs.delika.io/R")

# create version filter
version <- "0.0.1"
version_filter <- function(available) {
    available[available[, "Version"] == version, , drop = FALSE]
}
filters <- list(version_filter)

# install the package and its dependencies.
install.packages("delika", repos = repos, filters = filters)

delika.apiv1 Package

delika depends on delika.apiv1 package, which is an API client geenrated by OpenAPI generator.

delika Package

delika is a wrapper package of delika.apiv1 for ease of use.

References

Functions
  • delika::new_token(host, open_browser): Get JWT.
    • host: API host (default: https://api.delika.io/v1).
    • open_browser: Boolean value that indicates your program opens your browser at the point.
  • delika::read_token(key, path): Read JWT from local file.
    • key: Key.
    • path: Local file path (default: $HOME/.delika/token.json).
  • delika::new_client(token, host): Create a new instance of ApiClient.
    • token: JWT.
    • host: API host (default: https://api.delika.io/v1).
  • delika::load_client(key, path, host): Create a new instance of ApiClient.
    • key: Key.
    • path: Local file path (default: $HOME/.delika/token.json).
    • host: API host (default: https://api.delika.io/v1).
  • delika::read_delika_data(account_name, dataset_name, data_name, client): Read data into a data frame.
    • account_name: Account name.
    • dataset_name: Dataset name.
    • data_name: Data name.
    • client: ApiClient instance.
  • delika::read_delika_sql(sql, client, query_timeout_sec): Run SQL and read the results into a data frame.
    • sql: SQL.
    • client: ApiClient instance.
    • query_timeout_sec: Timeout in second (default: 30)
  • delika::read_delika_query_results(query_id, client): Read the query results into a data frame.
    • query_id: Query ID.
    • client: ApiClient instance.
  • delika::to_delika(data, account_name, dataset_name, data_name, client): Upload data frame.
    • data: Data frame.
    • account_name: Account name.
    • dataset_name: Dataset name.
    • data_name: Data name.
    • client: ApiClient instance.
R6 Classes
  • delika::Jwt: Data class to hold JWT
    • token_type: Bearer.
    • access_token: Access token.
    • access_token_expires_on: Expiration time of access token.
    • refresh_token: Refresh token.
    • refresh_token_exipres_on: Expiration time of refresh token.
    • refresh(client): Refresh the current JWT.
      • client: OpenAPI client. It is convenient to use delika.ApiClient.refresh_jwt() instead of calling this method directly.
    • save(key, path): Save the current token in the specified path.
      • key: Token name.
      • path: Token file path (default: ~/.delika/token.json for Linux or macOS, %APPDATA%\delika\token.json for Windows)
  • delika::ApiClient: A wrapper class for ApiClient generated by OpenAPI generator defined in delika.apiv1
    • token: JWT which is hold by the client.
    • host: The API host.
    • refresh_token(): Refresh the client's JWT.
    • get_user_datasets(): Get your datasets.
    • get_account_datasets(account_name): Get the list of account's datasets.
      • account_name: Account name.
    • get_dataset_data(account_name, dataset_name): Get the list of dataset's data.
      • account_name: Account name.
      • dataset_name: Dataset name.
    • upload_data(account_name, dataset_name, data_name, schema, source, force_generate_table_definition): Download data.
      • account_name: Account name.
      • dataset_name: Dataset name.
      • data_name: Data name.
      • schema: Data schema.
      • source: Local file path to upload.
      • force_generate_table_definition: Indicates whether TableDefinition in data schema is generated automatically and replaces if TableDefinition is defined in the data schema.
    • download_data(account_name, dataset_name, data_name, destination): Download data.
      • account_name: Account name.
      • dataset_name: Dataset name.
      • data_name: Data name.
      • destination: Local file path or buffer to save.
    • start_query(sql): Post the SQL.
      • sql: SQL.
    • get_query_status(query_id): Get the query status.
      • query_id: Query ID.
    • download_query_results(query_id, destination): Download the query results.
      • query_id: Query ID.
      • destination: Local file path or buffer to save.

Data Types

delika R
boolean logical
number numeric
factor factor
datetime POSIXct
text character

Examples

Basic Use

library(delika)

# get JWT (launch a browser)
token <- new_token()
# save JWT to the default path with the default key ('Default').
token$save()
# create a new API client.
client <- new_client(token)

# you can create a new API client from saved JWT.
# client <- load_client()

# work with the API client.
my_datasets <- client$get_user_datasets()
print(my_datasets)

# when your access_token is expired, you can refresh your JWT.
client$refresh_token()
# you need to save explicitly.
client$token.save()

Data Frame

# read data as a data frame.
df1 <- read_delika_data(account_name, dataset_name, data_name, client)

# read SQL results as a data frame.
df2 <- read_delika_sql(sql, client)

# upload from your data frame
to_delika(iris, account_name, dataset_name, data_name, client)

Version History

  • 0.0.2
    • Add read_delika_query_results function
  • 0.0.1
    • Initial release