Skip to content

Commit 04f6e36

Browse files
t1-t2 only gains difftime class optionally, for now
1 parent e2e0173 commit 04f6e36

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
1. `data.table(x=1, <expr>)`, where `<expr>` is an expression resulting in a 1-column matrix without column names, will eventually have names `x` and `V2`, not `x` and `V1`, consistent with `data.table(x=1, <expr>)` where `<expr>` results in an atomic vector, for example `data.table(x=1, cbind(1))` and `data.table(x=1, 1)` will both have columns named `x` and `V2`. In this release, the matrix case continues to be named `V1`, but the new behavior can be activated by setting `options(datatable.old.matrix.autoname)` to `FALSE`. See point 5 under Bug Fixes for more context; this change will provide more internal consistency as well as more consistency with `data.frame()`.
1010

11+
2. `t1 - t2`, where both `t1` and `t2` are `IDate`, will eventually have class `difftime`, consistent with the case where `t1` and `t2` are both `Date`. See point 17 under Bug Fixes for more context.
12+
1113
### NEW FEATURES
1214

1315
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 matches `DT[order(...)]` behavior with respect to locale. Thanks @rikivillalba for the suggestion and PR.

R/IDateTime.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ chooseOpsMethod.IDate = function(x, y, mx, my, cl, reverse) inherits(y, "Date")
130130
}
131131
ans = as.integer(unclass(e1) - unclass(e2))
132132
if (inherits(e2, "Date")) {
133-
setattr(ans, "class", "difftime")
134-
setattr(ans, "units", "days")
133+
if (!isTRUE(getOption("datatable.old.diff.date"))) {
134+
setattr(ans, "class", "difftime")
135+
setattr(ans, "units", "days")
136+
}
135137
} else {
136138
setattr(ans, "class", c("IDate", "Date"))
137139
}

R/onLoad.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@
9292
datatable.auto.index=TRUE, # DT[col=="val"] to auto add index so 2nd time faster
9393
datatable.use.index=TRUE, # global switch to address #1422
9494
datatable.prettyprint.char=NULL, # FR #1091
95-
datatable.old.matrix.autoname=TRUE # #7145: how data.table(x=1, matrix(1)) is auto-named set to change
95+
datatable.old.matrix.autoname=TRUE, # #7145: how data.table(x=1, matrix(1)) is auto-named set to change
96+
datatable.old.diff.date=TRUE # whether <IDate>-<IDate> gets difftime class set to change
9697
)
9798
opts = opts[!names(opts) %chin% names(options())]
9899
options(opts)

0 commit comments

Comments
 (0)