classic.Rmd
The classic API is probably the most intuitive to R users.
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")
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
.
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 list
s, we can convert those to list columns with, records_to_tibble
.
df <- records_to_tibble(records)
dplyr::glimpse(df)
#> Observations: 18
#> Variables: 8
#> $ record_id <chr> "rec0ews9ZIAHUI86P", "rec593llWKXu0FKpR", "…
#> $ record_created_time <dttm> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
#> $ `When?` <chr> "Before your first day", "First day", "Week…
#> $ Name <chr> "Complete your I-9 form and bring relevant …
#> $ `Complete?` <lgl> TRUE, NA, NA, TRUE, NA, TRUE, TRUE, NA, NA,…
#> $ `Relevant Resources` <list> [NULL, "rec3z3adT99u9XQPm", "recY5ekTUA112…
#> $ Notes <chr> NA, NA, "Our CEO, Jasmin, has a short orien…
#> $ Date <chr> NA, NA, "2019-04-17", NA, NA, NA, NA, NA, N…
We can retrieve a single record with retrieve_record
.
record <- retrieve_record(records[[1]]$id)
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
#> [1] "recwLOH4KysxwOZF1"
retrieve_record(rec)
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)
#> [1] TRUE
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)