Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ceiling_date doesn't work if NA present #486

Closed
adibender opened this issue Oct 22, 2016 · 1 comment · Fixed by #488
Closed

ceiling_date doesn't work if NA present #486

adibender opened this issue Oct 22, 2016 · 1 comment · Fixed by #488

Comments

@adibender
Copy link

adibender commented Oct 22, 2016

As of version 1.6.0, ceiling_date stopped working if the vector contains NA and unit minute, hour, or day (used to work in 1.5.6)

library(lubridate)
dates <- c("02/27/92", "02/27/92", "01/14/92", "02/28/92", "02/01/92")
times <- c("23:03:20", "22:29:56", "01:03:30", "18:21:03", "16:56:26")
x <- paste(dates, times)
times <- strptime(x, "%m/%d/%y %H:%M:%S")
times[2] <- NA

floor_date(times, unit="day") # works fine 
ceiling_date(times, unit="day") # breaks
Error in `[<-.POSIXlt`(`*tmp*`, not_same, value = c(699231600, NA, 695430000,  : 
  NAs are not allowed in subscripted assignments

These are the offending lines in round.R (if new or new1 contain NA):

not_same <- new1 != new
new1[not_same] <- new1[not_same] + delta
@cderv
Copy link
Contributor

cderv commented Oct 24, 2016

Hi,

I think we could make it work changing the subsetting with:

not_same <- which(new1 != new)
new1[not_same] <- new1[not_same] + delta

There is no error on subsetting this way and NA is still NA.

@vspinu, if you are ok with this fix I could make a PR adding some test.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants