diff --git a/NAMESPACE b/NAMESPACE index d96ab5cb28..c82f9cd10a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -149,16 +149,17 @@ S3method(as.POSIXct, IDate) S3method(as.POSIXct, ITime) S3method(as.POSIXlt, ITime) S3method(c, IDate) -S3method(cut, IDate) +S3method(c, ITime) S3method(format, ITime) S3method(IDateTime, default) S3method(mean, IDate) +S3method(mean, ITime) S3method(print, ITime) S3method(rep, IDate) S3method(rep, ITime) S3method(round, IDate) S3method(seq, IDate) -S3method(split, IDate) +S3method(seq, ITime) S3method(unique, IDate) S3method(unique, ITime) S3method('[<-', IDate) diff --git a/NEWS.md b/NEWS.md index 3da712bc7f..db3567860b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -132,6 +132,8 @@ 19. `merge.data,table` now retains any custom classes of the first argument, [#1378](https://github.com/Rdatatable/data.table/issues/1378). Thanks to @michaelquinn32 for reopening. +20. `c`, `seq` and `mean` of `ITime` objects now retain the `ITime` class via new `ITime` methods, [#3628](https://github.com/Rdatatable/data.table/issues/3628). Thanks @UweBlock for reporting. The `cut` and `split` methods for `ITime` have been removed since the default methods work, [#3630](https://github.com/Rdatatable/data.table/pull/3630). + #### NOTES 1. `rbindlist`'s `use.names="check"` now emits its message for automatic column names (`"V[0-9]+"`) too, [#3484](https://github.com/Rdatatable/data.table/pull/3484). See news item 5 of v1.12.2 below. diff --git a/R/IDateTime.R b/R/IDateTime.R index 2512f70525..179a736b62 100644 --- a/R/IDateTime.R +++ b/R/IDateTime.R @@ -49,11 +49,9 @@ as.Date.IDate = function(x, ...) { } mean.IDate = -cut.IDate = seq.IDate = c.IDate = rep.IDate = -split.IDate = unique.IDate = function(x, ...) { as.IDate(NextMethod()) @@ -258,6 +256,10 @@ unique.ITime = function(x, ...) { ans } +# various methods to ensure ITime class is retained, #3628 +mean.ITime = seq.ITime = c.ITime = function(x, ...) as.ITime(NextMethod()) + + # create a data.table with IDate and ITime columns # should work for most date/time formats like POSIXct diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index ea6107383f..bfadf57971 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -14977,6 +14977,10 @@ DT = data.table( test(2054, DT[order(C)[1:5], B, verbose=TRUE], c('b', 'b', 'c', 'c', 'a'), output = 'order optimisation is on') +# ITime class should be retained for same methods as IDate, #3628 +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)) ################################### # Add new tests above this line # diff --git a/man/IDateTime.Rd b/man/IDateTime.Rd index 3f04609869..42b612b567 100644 --- a/man/IDateTime.Rd +++ b/man/IDateTime.Rd @@ -17,16 +17,17 @@ \alias{as.POSIXct.ITime} \alias{as.POSIXlt.ITime} \alias{c.IDate} -\alias{cut.IDate} +\alias{c.ITime} \alias{format.ITime} \alias{IDateTime.default} \alias{mean.IDate} +\alias{mean.ITime} \alias{print.ITime} \alias{rep.IDate} \alias{rep.ITime} \alias{round.IDate} \alias{seq.IDate} -\alias{split.IDate} +\alias{seq.ITime} \alias{second} \alias{minute} \alias{hour}