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

ceiling_date doesn't work if NA present #486

Closed
adibender opened this Issue Oct 22, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@adibender

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

This comment has been minimized.

Show comment
Hide comment
@cderv

cderv Oct 24, 2016

Contributor

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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment