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

Add NA_Date_ and 0-length Date helpers #681

Closed
AshesITR opened this issue Jun 6, 2018 · 4 comments
Closed

Add NA_Date_ and 0-length Date helpers #681

AshesITR opened this issue Jun 6, 2018 · 4 comments

Comments

@AshesITR
Copy link

@AshesITR AshesITR commented Jun 6, 2018

Sometimes I find the need to explicitly set a date to NA (or specify an empty Date vector).
The former would be

NA_Date_ <- structure(NA_real_, class = "Date")

This is especially useful in conjuction with dplyr::if_else wich will error out on
dplyr::if_else(FALSE, NA_real_, lubridate::today()) and any other NA_...

The latter would be

Date <- function(length = 0L)structure(rep(NA_real_, length), class = "Date")

wich is very useful in allocating an empty data.frame with a date column.

@vspinu
Copy link
Member

@vspinu vspinu commented Jul 3, 2018

This is a good idea but it's so fundamental that should be tried with base R first. I could add NA_date_ and Date to lubridate but then I will have to add NA_POSIXct_ and POSIXct for consistency. I feel that all these belong in R proper.

@vspinu vspinu closed this in ea25ca6 Jul 3, 2018
@vspinu
Copy link
Member

@vspinu vspinu commented Jul 3, 2018

I decided to add these. We already do is.Date and is.POSIXct. Even if accepted into the core it almost surely won't be treating the tz argument as we want it - "UTC" by default.

@yakyak462
Copy link

@yakyak462 yakyak462 commented Jan 9, 2020

Hey -- sorry if this is obvious. But what is the workaround to not having NA_Date_ and needing to use if_else? The base R ifelse seems to breaks a lot of lubridate features.

@AshesITR
Copy link
Author

@AshesITR AshesITR commented Jan 10, 2020

@yakyak462 See the original issue: NA_Date_ <- structure(NA_real_, class = "Date").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.