RJSONIO
RJSONIO copied to clipboard
fromJSON(toJSON(117229)) equals 117230 (???)
It's as simple as that, numeric values are being corrupted when converted to JSON:
> toJSON(117229)
[1] "[ 1.1723e+05 ]"
> fromJSON(toJSON(117229))
[1] 117230
Perhaps there's some implicit conversion from double to float in the underlying C code?
Thanks.
This is caused by formatC() in the toJSON method for numeric vectors. A workaround is either toJSON(117229L) # i.e. treat as an integer vector/scalar or toJSON(117229, digits = 6)
I'll take a look at how best to fix it generally.
Thanks for the quick response. The workaround works perfectly.
Is there a simple way to ensure that digits=6 is always used across all my code? Some options variable that toJSON uses, for example?