Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upShould ymd() and similar return a date? #391
Comments
|
Indeed. The tz argument to |
|
I have implemented this locally and realized that it leads to some ocassionall inconveniences. When you need a POSIX object with HMS of
Our with_tz doesn't help either:
So you would need:
So I am leaving I am also leaving truncation functions alone for now. Till we have a clean and fast way to jump between Date and POSIX it's looks like bringing more hustle than it solves. Maybe we should consider a reverse of new |
|
Yeah I realised afterwards that changing rounding wouldn't be a good idea |
|
I also wondered if maybe |
It works if you pass the truncation parameter:
|
|
FYI This change might break existing ggplot visuals that plot according to a date variable and use some kind of scale_*_date(). Before you could get away with ymd("2013-01-01") type entries in your data frame and also in your scale_*_date(), and everything would work as expected. Now if you are plotting dates and want to adjust the scale, both the data frame and the argument to the scale function need a tz argument like ... ymd("2013-01-01", tz = "UTC"). Maybe ggplot2 could be updated to more gracefully handle Date objects (tz not specified, instead of POSIXct) as it effectively was doing before lubridate was updated?? Thanks |
|
Do you have concrete examples when ggplot doesn't handle Date objects "gracefully'? That should be reported on ggplot2 repo. |
|
@hadley this change had an unfortunate impact on comparison operators:
I think comparing Date and POSIX objects makes sense. So, I am considering overwriting Date Ops generic. What do you think? |
|
I'd rather push that towards R-core. |
|
Thanks for looking in to this! It looks like you have already nailed down the underlying problem, but here
works for all versionsdf <- data.frame(Date = ymd(c(20151231, 20160131, 20160228, 20160331)), only works with older versions of lubridatep <- p + scale_x_datetime(breaks = ymd(c("20160115", "20160215", you will see this error message when using newer versions ...#Error: Invalid input: time_trans works with objects of class POSIXct only update required to work with new and old lubridate.note the tz argument in both the data and the scale_x_datetime() functiondf <- data.frame(Date = ymd(c(20151231, 20160131, 20160228, 20160331), tz = On Sun, May 8, 2016 at 12:03 PM, Hadley Wickham notifications@github.com
|
I spent a good part of the night figuring how to do that. Nor S4 Compare group generic, nor S3 Ops worked as advertised. I eventually got all comparisons manually registered. Seem to work as expected now. Let's wait and see if this has any undesirable effects, and then propose to R-core. |
|
@hadley mentioned |
|
I would say no, "2016-08-30 EDT" is not meaningful generally. On the other hand, with global weather or financial data, the difference On Tue, Aug 30, 2016 at 1:38 PM, Abraham Neuwirth notifications@github.com
|
|
All rounding functions return POSIXct and that's very unlikely to change. So yes, rounding functions do preserve TZ because of that. |
Currently,
ymd()returns a POSIXct, which forces you to think about time zones. It seems like a reasonable principle to return a date in any situation where the time doesn't matter (this might include certainround_date()options).