bergant / airtabler

R interface to the Airtable API
Other
91 stars 16 forks source link

Cannot upload data.frame containing Boolean #4

Closed maelle closed 5 years ago

maelle commented 5 years ago

Thanks for a very useful package!

I've noticed I can't upload a data.frame containing Boolean columns unless I split it into its rows.

It's because unlist(as.list(records[i,]), recursive = FALSE) in air_insert_data_frame() transforms logicals into strings, therefore the subsequent call to jsonlite::toJSON() creates JSON that's not valid for the API. Cf example below,


record_data <- unlist(as.list(tibble::tibble(field1 = TRUE,
                              field2 = "myfield")), recursive = FALSE)

json_record_data <- jsonlite::toJSON(list(fields = record_data))
json_record_data
#> {"fields":["TRUE","myfield"]}

# What I'd want to get

record_data <- as.list(tibble::tibble(field1 = TRUE,
                                      field2 = "myfield"))

json_record_data <- jsonlite::toJSON(list(fields = record_data))
json_record_data
#> {"fields":{"field1":[true],"field2":["myfield"]}}

Created on 2019-01-08 by the reprex package (v0.2.1)

The small change in this PR works for me but I have not understood the role unlist played with to begin with so might be breaking other things. :wink:

bergant commented 5 years ago

Thank you for PR!

Yes, unlist is not a good idea here. One only needs to unlist when multiple values are inserted in one field (if it is multiple select type of field). This is now done on air_prepare_record.

maelle commented 5 years ago

Wow thanks for a super quick response! Awesome!