Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encode_batch_patch and encode_batch_post drop precision of numbers #16

Open
lstanton428 opened this issue Mar 13, 2024 · 1 comment
Open

Comments

@lstanton428
Copy link

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants