rc.Rmd
This document covers the RC (reference class) of rtable.
Create your rtable with the new
method, the method works in a fashion similar to setup
from the classic API.
Here we set up the session for the demo “Employee Onboarding” base and its “Onboarding Checklist” table. Note that by default the initialisation pulls the records from the table with list_records
. This can be turned off by setting the list_records
to FALSE
when initialising the object, as we demonstrate below.
library(rtable)
rt <- rtable$new(base = "appfSQILnns4mrSUr", table = "Onboarding Checklist", api_key = "xxXXxxxXXX", list_records = FALSE)
#> ❯ 0 records
#> ⚠ last updated at 2019-04-11 17:29:29
The rtable
object therefore does not include any record.
rt$list_records()
#> ❯ Fetching page 1
#> ✔ 18 records downloaded
This is particularly useful if you want to pass specific parameters to list_records
and do not want the whole table returned.
If you want to extract the records you can do so with.
rt$get_listed() %>%
dplyr::glimpse()
#> 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…
new_records <- dplyr::tibble(Name = c("Something", "Some other thing"))
rt$create_records(new_records)
#> ✔ Sucessfully created 2 records
You can then fetch the created records with.
(created <- rt$get_created())
#> # A tibble: 2 x 3
#> record_id record_created_time Name
#> <chr> <dttm> <chr>
#> 1 reco1vVhXNcWa84Eu 2019-12-04 07:58:56 Something
#> 2 recUB9dDHelbylEH1 2019-12-04 07:58:56 Some other thing
Now we can update the records we created.
update_records <- dplyr::tibble(
record_id = created$record_id,
Name = c("New Name", "Another new name")
)
rt$update_records(update_records, record_id)
#> ✔ Sucessfully updated 2 records
We can then return the updated records with.
(updated <- rt$get_updated())
#> # A tibble: 2 x 3
#> record_id record_created_time Name
#> <chr> <dttm> <chr>
#> 1 reco1vVhXNcWa84Eu 2019-12-04 07:58:56 New Name
#> 2 recUB9dDHelbylEH1 2019-12-04 07:58:56 Another new name
Important Note that at this point the records we initally pulled using the list_records
method have not been updated, only the remote Airtable was. We can can do so with.
rt$refresh()
#> ❯ Fetching page 1
#> ✔ 20 records downloaded
We see that it pulled 20 records as opposed to the 18 previously fetched because we created two new records.
rt$get_listed() %>%
nrow()
#> [1] 20
Finally, we can delete those two records we created and updated.
rt$delete_records(created, record_id)
#> ✔ Sucessfully deleted reco1vVhXNcWa84Eu
#> ✔ Sucessfully deleted recUB9dDHelbylEH1
#> ✔ Sucessfully deleted 2 records