You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I learned today that dates in R can sometimes be represented as integers, not just as doubles. This can occur like in the example below with seq, which changes the date-double into a date-integer. It seems like an unorthodox data type and might be thought of as a bug of seq that it came to be at all. Unexpectedly, pivot_longer converts these date-integers into the typical date-double, and I couldn't figure out a way to undo that.
This is actually intentional. Date vectors are really meant to be double (for better or worse), and it has been a longstanding bug that they are sometimes returned as integer by base R functions. seq.Date() was actually fixed in R 4.2, and now returns a double vector:
Somewhere under the hood, vctrs is "normalizing" or "fixing" the integer date vector and turning it into a double vector. We generally want this behavior, so I would call this expected.
Unfortunately there isn't a great place to document this, but I expect it to come up less often now that R 4.2+ will generate integer Date vectors less often
I learned today that dates in R can sometimes be represented as integers, not just as doubles. This can occur like in the example below with
seq
, which changes the date-double into a date-integer. It seems like an unorthodox data type and might be thought of as a bug ofseq
that it came to be at all. Unexpectedly,pivot_longer
converts these date-integers into the typical date-double, and I couldn't figure out a way to undo that.I'm not sure where this would cause problems for someone, but I was surprised to see one of my answers on SO did not exactly match the original data because of this subtle change. https://stackoverflow.com/questions/71972396/how-to-reduce-processing-time-of-a-code-in-r
The text was updated successfully, but these errors were encountered: