From 63f1a73df92c4942ba93ecd21cc29d790b54d25f Mon Sep 17 00:00:00 2001 From: Ivan K Date: Fri, 20 Feb 2026 11:46:58 +0300 Subject: [PATCH 1/3] is.numeric() = FALSE for IDate, ITime --- NAMESPACE | 2 ++ R/IDateTime.R | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 8381a14a73..5caa110df1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -198,6 +198,8 @@ S3method(rep, IDate) S3method(rep, ITime) S3method(round, IDate) S3method(round, ITime) +S3method(is.numeric, IDate) +S3method(is.numeric, ITime) S3method(trunc, ITime) S3method(seq, IDate) S3method(seq, ITime) diff --git a/R/IDateTime.R b/R/IDateTime.R index 49fa5abda2..8b4a008275 100644 --- a/R/IDateTime.R +++ b/R/IDateTime.R @@ -90,6 +90,8 @@ round.IDate = function(x, digits=c("weeks", "months", "quarters", "years"), ...) quarters = ISOdate(year(x), 3L * (quarter(x)-1L) + 1L, 1L), years = ISOdate(year(x), 1L, 1L))) } +# Dates aren't simple numbers, and round.IDate doesn't accept numeric 'digits'. +is.numeric.IDate = function(x) FALSE chooseOpsMethod.IDate = function(x, y, mx, my, cl, reverse) inherits(y, "Date") @@ -248,6 +250,9 @@ round.ITime = function(x, digits = c("hours", "minutes"), ...) "class", "ITime")) } +# Day times aren't simple numbers, and round.ITime doesn't accept numeric 'digits'. +is.numeric.ITime = function(x) FALSE + trunc.ITime = function(x, units = c("hours", "minutes"), ...) { (setattr(switch(match.arg(units), From 8054985ee1b51a6409b78e8a9d0f4d0565114fa2 Mon Sep 17 00:00:00 2001 From: Ivan K Date: Sat, 18 Jul 2026 22:20:35 +0300 Subject: [PATCH 2/3] Avoid mean() warning Unclass so that mean() -> is.numeric() doesn't warn. --- R/IDateTime.R | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/R/IDateTime.R b/R/IDateTime.R index 845c1460fb..64b7b32334 100644 --- a/R/IDateTime.R +++ b/R/IDateTime.R @@ -51,6 +51,10 @@ as.Date.IDate = function(x, ...) { } mean.IDate = + function(x, ...) { + x = unclass(x) + as.IDate(NextMethod()) + } seq.IDate = c.IDate = cut.IDate = @@ -277,7 +281,11 @@ unique.ITime = function(x, ...) { } # various methods to ensure ITime class is retained, #3628 -mean.ITime = seq.ITime = c.ITime = function(x, ...) as.ITime(NextMethod()) +mean.ITime = function(x, ...) { + x = unclass(x) + as.ITime(NextMethod()) +} +c.ITime = seq.ITime = function(...) as.ITime(NextMethod()) # create a data.table with IDate and ITime columns From 0eab566b509de1acea3f1d77299e09d9bf431f99 Mon Sep 17 00:00:00 2001 From: Ivan K Date: Sat, 18 Jul 2026 23:06:15 +0300 Subject: [PATCH 3/3] Exercise mean.IDate --- inst/tests/tests.Rraw | 1 + 1 file changed, 1 insertion(+) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 00973ae3a5..4e3ea6d807 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -15090,6 +15090,7 @@ test(2054, DT[order(C)[1:5], B, verbose=TRUE], c('b', 'b', 'c', 'c', 'a'), test(2055.1, seq(from = as.ITime('00:00:00'), to = as.ITime('00:00:05'), by = 5L), as.ITime(c(0, 5L))) test(2055.2, c(as.ITime(0L), as.ITime(1L)), as.ITime(c(0L, 1L))) test(2055.3, mean(as.ITime(c(0L, 0L))), as.ITime(0L)) +test(2055.4, mean(as.IDate(c(0L, 0L))), as.IDate(0L)) # as.data.table.array some of dimnames are NULL, #3636 a = array(1:8, dim=c(2L,2L,2L), dimnames=list(NULL, NULL, as.character(1:2)))