Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register the full IDate S3 class for S4 dispatch #6844

Merged
merged 3 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

1. New `sort_by()` method for data.tables, [#6662](https://github.com/Rdatatable/data.table/issues/6662). It uses `forder()` to improve upon the data.frame method and also match `DT[order(...)]` behavior with respect to locale. Thanks @rikivillalba for the suggestion and PR.

## BUG FIXES

1. Custom binary operators from the `lubridate` package now work with objects of class `IDate` as with a `Date` subclass, [#6839](https://github.com/Rdatatable/data.table/issues/6839). Thanks @emallickhossain for the report and @aitap for the fix.

# data.table [v1.17.0](https://github.com/Rdatatable/data.table/milestone/34) (20 Feb 2025)

## POTENTIALLY BREAKING CHANGES
Expand Down
3 changes: 1 addition & 2 deletions R/AllS4.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ if ("package:data.table" %in% search()) stopf("data.table package loaded. When d

## Allows data.table to be defined as an object of an S4 class,
## or even have data.table be a super class of an S4 class.
methods::setOldClass(c('data.frame'))
methods::setOldClass(c('data.table', 'data.frame'))

## as(some.data.frame, "data.table")
Expand All @@ -16,7 +15,7 @@ methods::setAs("data.table", "data.frame", function(from) {
as.data.frame(from)
})

methods::setOldClass("IDate")
methods::setOldClass(c("IDate", "Date"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

up on L6 I see multiple calls for a similar case on the data.table/data.frame class. should we remove the one-class call there, or is there benefit from having both calls here too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based on the description of the test= argument I guess we should remove L6

methods::setOldClass("ITime")

methods::setAs("character", "IDate", function(from) as.IDate(from))
Expand Down
8 changes: 8 additions & 0 deletions inst/tests/S4.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,11 @@ test(7.1, is.data.table(DF@x))
# Similar code for under-allocated data.tables in S4 slots, #6704
setClass("DataTable", slots=c(x="data.table"))
test(7.2, options=c(datatable.alloccol=0L), {DT = new("DataTable", x=data.table(a=1)); DT@x[, b := 2L]; DT@x$b}, 2L) # NB: requires assigning DT to test assignment back to that object

# IDate was not visible as Date to S4 dispatch, #6839
CustomDurationClass <- setClass("CustomDurationClass", contains = "integer")
setGeneric("%foo%", function(e1, e2) stop("dispatch to default method"))
setMethod(`%foo%`, c("Date", "CustomDurationClass"), function (e1, e2) e1 - [email protected])
test(8, as.IDate("2025-03-01") %foo% CustomDurationClass(1), as.IDate("2025-02-28"))
removeGeneric("%foo%")
removeClass("CustomDurationClass")
Loading