knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

The classic API is probably the most intuitive to R users.

Setup

First, set up your session with the setup function. The function will let you pass your api_key (required), and optionally a base, and a table. Here we set up the session for the demo "Employee Onboarding" base.

Here we set up the session for the demo "Employee Onboarding" base and its "Onboarding Checklist" table.

library(rtable)
setup(api_key = "xxXXxxxXXx", base = "appfSQILnns4mrSUr", table = "Onboarding Checklist")
library(rtable)
setup(base = "appfSQILnns4mrSUr", table = "Onboarding Checklist")

Note that you can set up your api_key as a global variable by adding the option below to your .Renviron or .Rprofile.

options("RTABLE_API_KEY" = "xXxxXXXxx")

You can check what has been set up with.

get_setup()

You can always reset the setup with reset_setup.

Get

We can then list records with the list_records function. Since we specified a base, a table and a view in our setup function we do not need to do so here. If you had not setup the latter previously you can specify them in list_records.

records <- list_records()

Note that all functions return lists, we can convert those to list columns with, records_to_tibble.

df <- records_to_tibble(records)
dplyr::glimpse(df)

We can retrieve a single record with retrieve_record.

record <- retrieve_record(records[[1]]$id)

Create

We can create a new record with create_records

df <- data.frame(Name = "It's me")
created <- create_records(df)

To demonstrate that it worked we can retrieve it again with retrieve_record

(rec <- created[[1]]$id) # we'll need it later
retrieve_record(rec)

Update

We can update records with update_record. Let's update the one we just created.

df <- data.frame(Name = "It's me again!", record_id = rec)
updated <- update_records(df, record_id)

We'll retrieve the record we updated and see if it matches the one we updated.

updated_record <- retrieve_record(rec)
identical(list(updated_record), updated)

Delete

Finally, we can delete the record we created and updaed.

delete_record(rec)

Then retrieving the deleted record should error as the record we want to retrieve is inexistent.

retrieve_record(rec)


JohnCoene/rtable documentation built on May 8, 2019, 7:37 a.m.