-
Notifications
You must be signed in to change notification settings - Fork 52
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
datetimes are different after gs4 write/read round trip #273
Comments
I'm doing issue triage prior to a release that's under deadline. But from a quick read, I think this may be a combination of R FAQ 7.31 (https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f) with a light sprinkling of (insert something about POSIXct formatting here). I feel like there's something I can point to about POSIXct formatting and hopefully I'll come back to add it. This is likely a #wontfix. |
Coming back just to park a small example from @DavisVaughan about some of the joys of POSIXct. Again, I'm not really digging it to this just yet, but want to leave myself some notes.
|
A little investigation of my own. The date-time we used above is:
converting that to google sheet form using the algorithm in
now, deep in the stack we eventually call
So we lost some precision. And indeed if you go to the google sheet that was created and convert the cell to Number format you'll see If you reverse the algorithm with this you get:
It is also worth noting that googlesheets4 doesn't "reverse the algorithm" in exactly this way, but i think it should. Instead inside
Note that doing the math that way gave a slightly different answer than above, and I think it is slightly less correct, but this does reproduce the time difference of |
And that jsonlite failure seems to come from an internal helper called Browse[14]> jsonlite:::num_to_char(44783.859282407407591, digits = 22)
[1] "44783.8592824074"
Browse[14]> format(44783.859282407407591, digits = 22)
[1] "44783.85928240740759065" |
It seems to limit @jeroen, any idea why that is? |
Ha oh shoot if you just update to dev jsonlite then the jsonlite part of this is actually fixed: > unclass(df$dt)/86400 + 25569
[1] 44783.85928240740759065
attr(,"tzone")
[1] "UTC"
> jsonlite::fromJSON(jsonlite::toJSON(unclass(df$dt)/86400 + 25569, digits = 22))
[1] 44783.85928240740759065 Fixed by jeroen/jsonlite#413, which raised the cap from 15 to 17 digits (and 17 actually works) It was argued for here jeroen/jsonlite#350, since IEEE754 doubles converted to string with 17 significant digits must be able to roundtrip themselves |
I did a little study of this and, at least with this example, the jsonlite fix is the only thing that touches it. Changing the order of operations in googlesheets4 when converting from a spreadsheet date time to @jeroen Can you note this down as a reason in favor of a jsonlite release? TL;DR the 17 significant digits are necessary for roundtripping datetimes between R and Google Sheets. |
OK I'll do that today. |
Where exactly does jsonlite get invoked in this stack? We might have to backpaddle a little bit on the default in jsonlite because of jeroen/jsonlite#420, but if you explicitly set |
I can't re-trace this right this moment, but I have no reason to doubt @DavisVaughan's research described above in #273 (comment).
Also based on my memory, I think the jsonlite usage, on the "write" side, is likely to all be going through httr. |
Writing datetimes to a Google Sheet with googlesheets4 and then re-reading it with the column formatted as a datetime alters the value. The change is very small and is not always noticeable with R's default print options.
I've included only a single datetime in the reprex because it shows a difference after printing.
The text was updated successfully, but these errors were encountered: