Closed danielvartan closed 8 months ago
This warning is related to the last lubridate
update (version 1.9.0).
roll
argument to updating and time-zone manipulation functions is deprecated in favor of a newroll_dst
parameter.
I identified the warning trigger. It comes from the POSIXct
method of start_window()
and end_window()
.
start_window.POSIXct <- function(x, y = NULL, ...) {
if (is_null(y)) {
min(x)
} else {
abort_not_chr(y, class = "POSIXct")
assertTime(y)
y <- utctime(y, tz = "UTC")
force_tz(y, tz(x), roll = TRUE)
}
}
end_window.POSIXct <- function(x, y = NULL, ...) {
if (is_null(y)) {
max(x) + period(1, "second")
} else {
abort_not_chr(y, class = "POSIXct")
assertTime(y)
lgl_date <- nchar(y) > 7 & nchar(y) < 11
lgl_yrmth <- nchar(y) < 9 & nchar(y) > 4
lgl_yr <- nchar(y) < 5
y <- utctime(y, tz = "UTC")
y <- force_tz(y, tz(x), roll = TRUE)
if (any(lgl_date)) {
y[lgl_date] <- y[lgl_date] + period(1, "day")
}
if (any(lgl_yrmth)) {
y[lgl_yrmth] <- rollback(
y[lgl_yrmth] + period(1, "month"),
roll_to_first = TRUE
)
}
if (any(lgl_yr)) {
y[lgl_yr] <- y[lgl_yr] + period(1, "year")
}
lgl_time <- !(lgl_date | lgl_yrmth | lgl_yr)
y[lgl_time] <- y[lgl_time] + 1
y
}
}
Source: https://github.com/tidyverts/tsibble/blob/main/R/filter-index.R#L196
The deprecated roll
argument had the following description:
#' @param roll logical. If TRUE, and `time` falls into the DST-break, assume
#' the next valid civil time, otherwise return NA. See examples.
Example:
# DST start for time zone "America/New_York" in 2010 ("skipped" transition)
# DST-break: 2010-03-14 02:00:00--2010-03-14 02:59:59
ymd_hms("2010-03-14 01:59:59", tz = "America/New_York")
#> [1] "2010-03-14 01:59:59 EST"
ymd_hms("2010-03-14 02:00:00", tz = "America/New_York")
#> [1] NA
ymd_hms("2010-03-14 03:00:00", tz = "America/New_York")
#> [1] "2010-03-14 03:00:00 EDT"
# DST end for time zone "America/New_York" in 2010 ("repeated" transition")
# Rollback: 2010-11-07 02:00:00 -> 2010-11-07 01:00:00
library(lubridate)
x <- ymd_hms("2010-03-14 02:30:00", tz = "UTC")
force_tz(x, "America/New_York", roll = FALSE)
#> [1] NA
force_tz(x, "America/New_York", roll = TRUE)
#> [1] "2010-03-14 03:00:00 EDT"
See: Clock changes in New York, New York, USA. See: How does Daylight Saving Time work?.
The roll
argument have been replaced with roll_dst
.
#' @param roll deprecated, same as `roll_dst` parameter.
Source: https://github.com/tidyverse/lubridate/blob/main/R/time-zones.r#L74
roll_dst
comes from the timechange
package and have the following description.
##' @param roll_dst is a string vector of length one or two. When two values are
##' supplied they specify how to roll date-times when they fall into "skipped" and
##' "repeated" DST transitions respectively. A single value is replicated to the
##' length of two. Possible values are:
##'
##' * `pre` - Use the time before the transition boundary.
##' * `boundary` - Use the time exactly at the boundary transition.
##' * `post` - Use the time after the boundary transition.
##' * `xfirst` - crossed-first: First time which occurred when crossing the
##' boundary. For addition with positive units pre interval is crossed first and
##' post interval last. With negative units post interval is crossed first, pre -
##' last. For subtraction the logic is reversed.
##' * `xlast` - crossed-last.
##' * `NA` - Produce NAs when the resulting time falls inside the problematic interval.
Source: https://github.com/vspinu/timechange/blob/main/R/addition.R#L17
Hence, if we want to mimic the behavior of roll = TRUE
, we should use roll_dst = c("boundary", "post")
.
Example:
library(lubridate)
# DST start for time zone "America/New_York" in 2010 ("skipped" transition)
# DST-break: 2010-03-14 02:00:00--2010-03-14 02:59:59
x <- ymd_hms("2010-03-14 02:30:00", tz = "UTC")
force_tz(x, "America/New_York", roll = TRUE)
#> [1] "2010-03-14 03:00:00 EDT"
force_tz(x, "America/New_York", roll_dst = c("boundary", "post"))
#> [1] "2010-03-14 03:00:00 EDT"
# DST end for time zone "America/New_York" in 2010 ("repeated" transition")
# Rollback: 2010-11-07 02:00:00 -> 2010-11-07 01:00:00
x <- ymd_hms("2010-11-07 01:30:00", tz = "UTC")
force_tz(x, "America/New_York", roll = TRUE)
#> [1] "2010-11-07 01:30:00 EST"
force_tz(x, "America/New_York", roll_dst = c("boundary", "post"))
#> [1] "2010-11-07 01:30:00 EST"
I'm preparing a pull-request with this change.
Hi there,
The
tsibble
package is giving a warning related to a deprecated argument (roll
) in thelubridate
package. According to the warning, theroll
argument was deprecated in version1.8.4
.You can reproduce this warning with the code below. Please note that you first need to install the
actverse
package.Created on 2022-11-12 with reprex v2.0.2