Problem:
unique() currently fails to return the unique values for {lubridate} Period objects, which causes issues when trying to check data with check_data().
Steps to reproduce this behaviour:
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
library(chk)
x <- lubridate::hms(c("00:00:00", "24:00:00", NA_character_))
x
#> [1] "0S" "24H 0M 0S" NA
unique(x)
#> [1] 0 NA
check_data(data.frame(period = hms("01:02:03")), list(period = x))
#> Error in `lapply()`:
#> ! All elements of `data.frame(period = hms("01:02:03"))$period` must be equal to 0.
#> Use `rlang::last_error()$y` to show the object compared to.
#> Run `rlang::last_trace()` to see where the error occurred.
unique.Period <- function(x, ...) {
x |>
as.character(x) |>
unique() |>
as.period()
}
unique(x)
#> [1] "0S" "24H 0M 0S" NA
check_data(data.frame(period = hms("01:02:03")), list(period = x)) # passes
Expected output/desired solution:
See reprex above.
Problem:
unique()currently fails to return the unique values for{lubridate}Periodobjects, which causes issues when trying to check data withcheck_data().Steps to reproduce this behaviour:
Expected output/desired solution:
See reprex above.