From 0e3ca89caf0d4986f8e54a2912b1a43f61a5332f Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Thu, 21 Aug 2025 22:03:53 +0000 Subject: [PATCH 1/3] #18938: seq(, , by=1) "just works" --- src/library/base/R/dates.R | 6 +++--- tests/datetime3.R | 14 +++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) 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..cecf9ecad11 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(as.Date(from_str), "2025-10-01", by="months"), + seq(as.Date(from_str), as.Date("2025-10-01"), by="months")) +}) ## keep at end rbind(last = proc.time() - .pt, From 769bcc6dc98f2780f12f901631c52b94915b5be3 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Thu, 21 Aug 2025 22:09:38 +0000 Subject: [PATCH 2/3] 3 more tests --- tests/datetime3.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/datetime3.R b/tests/datetime3.R index cecf9ecad11..549d2e934fe 100644 --- a/tests/datetime3.R +++ b/tests/datetime3.R @@ -795,6 +795,9 @@ stopifnot(exprs = { 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) identical(seq(as.Date(from_str), "2025-10-01", by="months"), seq(as.Date(from_str), as.Date("2025-10-01"), by="months")) From 0ad562f3367922c79f138ac92517c49ac96a2c22 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Thu, 21 Aug 2025 22:39:19 +0000 Subject: [PATCH 3/3] remove an indirectly-related test --- tests/datetime3.R | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/datetime3.R b/tests/datetime3.R index 549d2e934fe..9a200b526fc 100644 --- a/tests/datetime3.R +++ b/tests/datetime3.R @@ -798,9 +798,6 @@ stopifnot(exprs = { 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) - - identical(seq(as.Date(from_str), "2025-10-01", by="months"), - seq(as.Date(from_str), as.Date("2025-10-01"), by="months")) }) ## keep at end