You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: NEWS.md
+15Lines changed: 15 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -107,6 +107,21 @@
107
107
108
108
18. `fwrite` now allows `dec` to be the same as `sep` for edge cases where only one will be written, e.g. 0-row or 1-column tables. [#7227](https://github.com/Rdatatable/data.table/issues/7227). Thanks @MichaelChirico for the report and @venom1204 for the fix.
109
109
110
+
22. Using `by=` or `keyby=` with a simple numeric or character vector in `j` (e.g. `DT[, 1:2, by=grp]`) used to silently ignore the grouping argument. This now issues a warning to alert the user that grouping is not applied in this syntax and guides them to use the `.SD` idiom instead. [#5397](https://github.com/Rdatatable/data.table/issues/5397). Thanks to @mcol for the report and @venom1204 for the fix.
111
+
112
+
```r
113
+
DT = data.table(a=1:4, grp=c(1,1,2,2))
114
+
DT[, 1, by = grp]
115
+
# a
116
+
# <int>
117
+
# 1: 1
118
+
# 2: 2
119
+
# 3: 3
120
+
# 4: 4
121
+
# Warning message:
122
+
# `by` or `keyby` is ignored when `j` is a numeric vector...
123
+
```
124
+
110
125
### NOTES
111
126
112
127
1. The following in-progress deprecations have proceeded:
# else the NA in ansvals are for join inherited scope (test 1973), and NA could be in irows from join and data in i should be returned (test 1977)
763
769
# in both cases leave to the R-level subsetting of i and x together further below
764
770
} elseif (is.numeric(j)) {
771
+
if (!missingby) {
772
+
warning(
773
+
"`by` or `keyby` is ignored when `j` is a numeric vector used for column selection. ", "Perhaps you intended to use `.SD`? For example: DT[, .SD[, ", deparse(jsub), "], by = ...]")
774
+
}
765
775
j= as.integer(j)
766
776
if (any(w<- (j>ncol(x)))) stopf("Item %d of j is %d which is outside the column number range [1,ncol=%d]", idx<- which.first(w), j[idx], ncol(x))
See \href{../doc/datatable-intro.html}{\code{vignette("datatable-intro")}} and \code{example(data.table)}.}
99
99
100
-
\item{by}{ Column names are seen as if they are variables (as in \code{j} when \code{with=TRUE}). The \code{data.table} is then grouped by the \code{by} and \code{j} is evaluated within each group. The order of the rows within each group is preserved, as is the order of the groups. \code{by} accepts:
101
-
100
+
\item{by}{ Column names are seen as if they are variables (as in \code{j} when \code{with=TRUE}). \emph{Note that `by` and `keyby` are ignored when `j` is a character or numeric vector used for selecting columns (i.e., when the internal `with=FALSE` is triggered).} The \code{data.table} is then grouped by the \code{by} and \code{j} is evaluated within each group. The order of the rows within each group is preserved, as is the order of the groups. \code{by} accepts:
101
+
102
102
\itemize{
103
103
\item A single unquoted column name: e.g., \code{DT[, .(sa=sum(a)), by=x]}
0 commit comments