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

fromJSON(toJSON(117229)) equals 117230 (???) #9

Open
asieira opened this issue Feb 5, 2014 · 2 comments
Open

fromJSON(toJSON(117229)) equals 117230 (???) #9

asieira opened this issue Feb 5, 2014 · 2 comments

Comments

@asieira
Copy link

asieira commented Feb 5, 2014

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?

@duncantl
Copy link
Owner

duncantl commented Feb 5, 2014

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.

@asieira
Copy link
Author

asieira commented Feb 5, 2014

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?

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