diff --git a/src/library/base/R/dates.R b/src/library/base/R/dates.R index d2c4bfebc18..a42f4d5cc75 100644 --- a/src/library/base/R/dates.R +++ b/src/library/base/R/dates.R @@ -293,9 +293,9 @@ seq.Date <- function(from, to, by, length.out = NULL, along.with = NULL, ...) if(is.na(by)) stop("'by' is NA") res <- switch(missing_arg, - from = seq.int(to = unclass(to), by = by, length.out = length.out), - to = seq.int(from = unclass(from), by = by, length.out = length.out), - length.out = seq.int(from = unclass(from), to = unclass(to), by = by) + from = seq.int(to = unclass(as.Date(to)), by = by, length.out = length.out), + to = seq.int(from = unclass(as.Date(from)), by = by, length.out = length.out), + length.out = seq.int(from = unclass(as.Date(from)), to = unclass(as.Date(to)), by = by) ) .Date(res) } diff --git a/tests/datetime3.R b/tests/datetime3.R index 883e4ebbd9b..9a200b526fc 100644 --- a/tests/datetime3.R +++ b/tests/datetime3.R @@ -786,7 +786,19 @@ identicalPlt <- function(x, y, ...) stopifnot(identicalPlt(z1, z), identicalPlt(z2, z)) ## failed previously, incl in rev 88441 - +## strings in one argument of seq.Date always get coerced +from_str <- "2025-01-01"; to_str <- "2025-01-07" +full_seq <- seq(as.Date(from_str), as.Date(to_str)) +stopifnot(exprs = { + identical(seq(as.Date(from_str), to_str), full_seq) + identical(seq(as.Date(from_str), to_str, by=1L), full_seq) + identical(seq(as.Date(from_str), to_str, length.out=7L), full_seq) + identical(seq(to=as.Date(to_str), length.out=7L, by=1L), full_seq) + identical(seq(from=as.Date(from_str), length.out=7L, by=1L), full_seq) + identical(seq(to=as.Date(to_str), from_str), full_seq) + identical(seq(to=as.Date(to_str), from_str, by=1L), full_seq) + identical(seq(to=as.Date(to_str), from_str, length.out=7L), full_seq) +}) ## keep at end rbind(last = proc.time() - .pt,