rairtable is an efficient, Tidyverse-friendly interface to Airtable API intended to simplify the integration of Airtable into data science workflows. Other R packages exist for this purpose, but
rairtable offers the following advantages:
Generate an Airtable API key from your Airtable account page and pass the result to
set_airtable_api_key('MY_KEY_HERE'). If you would like to store the key in your
.Renviron file for use in the future, set
set_airtable_api_key('MY_KEY_HERE', install = TRUE).
table <- airtable('TABLE_NAME', 'BASE_ID') view <- airtable('TABLE_NAME', 'BASE_ID', view = 'VIEW_NAME')
rairtable::airtable() creates an
airtable object that is used in a similar fashion to a database connection. The resulting object is then passed to other
airtable_data <- read_airtable(airtable_object, id_to_col = TRUE, max_rows = 50000)
read_airtable() will read all rows in the chosen table and store Airtable records IDs in a column named
airtable_record_id. Optionally, airtable record IDs can be stored as row names for convenience.
Row names are bad practice in most cases. For this application, they offer the advantage of being sticky through most subset and transform operations which allows us to retain the record ID by default. Some operations will destroy row names (e.g. the use of
dplyr::arrange()). For these reasons, the default behavior is to store the record IDs in a column. Airtable record IDs are necessary for update and delete operations, but otherwise can be ignored.
rairtable is intended to slot into existing data processing workflows.
table <- airtable('mtcars', 'appXXXXXXXXXXXXXX') cars_airtable <- read_airtable(table) # change units of qsec to minutes cars_airtable %>% mutate(qsec = qsec/60) %>% update_records(table, columns = qsec) # remove records where mpg is less than 12 cars_airtable %>% filter(mpg < 12) %>% delete_records(table)