matthewjrogers / rairtable

Efficient, Tidyverse-friendly wrapper for the Airtable API
https://matthewjrogers.github.io/rairtable/
Other
13 stars 4 forks source link

encode_batch_patch and encode_batch_post drop precision of numbers #16

Open lstanton428 opened 6 months ago

lstanton428 commented 6 months ago

Describe the bug encode_batch_patch() and encode_batch_post() (and likely anywhere else that) use jsonlite's toJSON() function. This presents a problem, as the function defaults to only allowing 4 digits of precision after the decimal place. There are many cases when that precision is necessary (like with lat/lng data).

To Reproduce

jsonlite::toJSON(list(lat = 1.9993292939931929), digits = 10000) {"lat":[1.9993292939931928]} jsonlite::toJSON(list(lat = 1.9993292939931929)) {"lat":[1.9993]}

Expected behavior Preferably no precision would be lost. Consider different packages for converting to JSON or set digits to something higher.

matthewjrogers commented 6 months ago

Per this stackoverflow question the issue seems to have to do with JSON itself only supporting floats which have a maximum specificity. Even setting digits = 1000, I see truncation in your example.

jsonlite::toJSON(list(lat = 1.9993292939931929), digits = 10000)
# prints the following -- note the missing final two digits
{"lat":[1.99932929399319]} 

You can set digits globally, incidentally, e.g. options(digits = 1000), but I don't think it will solve your problem.

Unfortunately, since the Airtable API only accepts JSON payloads, this is likely to persist no matter what package we use internally or what interface to the API you use.