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
+1-22Lines changed: 1 addition & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -131,28 +131,7 @@ rowwiseDT(
131
131
132
132
18. Grouped queries on keyed tables no longer return an incorrectly keyed result if the _ad hoc_ `by=` list has some function call (in particular, a function which happens to return a strictly decreasing function of the keys), e.g. `by=.(a = rev(a))`, [#5583](https://github.com/Rdatatable/data.table/issues/5583). Thanks @AbrJA for the report and @MichaelChirico for the fix.
133
133
134
-
19. Assigning `list(NULL)` to a list column now replaces the column with `list(NULL)`, instead of deleting the column [#5558](https://github.com/Rdatatable/data.table/issues/5558). This behavior is now consistent with base `data.frame`. Thanks @tdhock for the report and @joshhwuu for the fix. This is due to a fundamental ambiguity from both allowing list columns _and_ making the use of `list()` to wrap `j=` arguments optional. We think that the code behaves as expected in all cases now. See the below for some illustration:
135
-
136
-
```r
137
-
DT = data.table(L=list(1L), i=2L, c='a')
138
-
139
-
DT[, i := NULL] # delete i
140
-
DT[, L := NULL] # delete L
141
-
142
-
DT[, i := list(NULL)] # overwrite: identical(DT$i, list(NULL))
143
-
# ^ ** THIS IS A CHANGE FROM PREVIOUS BEHAVIOR WHICH WOULD DELETE i **
144
-
DT[, L := list(NULL)] # assignment: identical(DT$L, list(NULL))
145
-
146
-
DT[, i := .(3L)] # assignment: identical(DT$i, 3L)
147
-
DT[, i := .('a')] # overwrite: identical(DT$i, 'a')
148
-
DT[, L := .(list(NULL))] # assignment: identical(DT$L, list(NULL))
DT[, c('L', 'i') := list(NULL, 3L)] # delete L, assign to i
153
-
DT[, c('L', 'i') := list(list(NULL), NULL)] # assign to L, delete i
154
-
```
155
-
20. An integer overflow in `fread()` with lines longer than `2^(31/2)` bytes is prevented, [#6729](https://github.com/Rdatatable/data.table/issues/6729). The typical impact was no worse than a wrong initial allocation size, corrected later. Thanks to @TaikiSan21 for the report and @aitap for the fix.
134
+
19. An integer overflow in `fread()` with lines longer than `2^(31/2)` bytes is prevented, [#6729](https://github.com/Rdatatable/data.table/issues/6729). The typical impact was no worse than a wrong initial allocation size, corrected later. Thanks to @TaikiSan21 for the report and @aitap for the fix.
Copy file name to clipboardExpand all lines: man/assign.Rd
-2Lines changed: 0 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -78,8 +78,6 @@ When \code{LHS} is a factor column and \code{RHS} is a character vector with ite
78
78
Unlike \code{<-} for \code{data.frame}, the (potentially large) LHS is not coerced to match the type of the (often small) RHS. Instead the RHS is coerced to match the type of the LHS, if necessary. Where this involves double precision values being coerced to an integer column, a warning is given when fractional data is truncated. It is best to get the column types correct up front and stick to them. Changing a column type is possible but deliberately harder: provide a whole column as the RHS. This RHS is then \emph{plonked} into that column slot and we call this \emph{plonk syntax}, or \emph{replace column syntax} if you prefer. By needing to construct a full length vector of a new type, you as the user are more aware of what is happening and it is clearer to readers of your code that you really do intend to change the column type; e.g., \code{DT[, colA:=as.integer(colA)]}. A plonk occurs whenever you provide a RHS value to `:=` which is \code{nrow} long. When a column is \emph{plonked}, the original column is not updated by reference because that would entail updating every single element of that column whereas the plonk is just one column pointer update.
79
79
80
80
\code{data.table}s are \emph{not} copied-on-change by \code{:=}, \code{setkey} or any of the other \code{set*} functions. See \code{\link{copy}}.
81
-
82
-
While in most cases standard and functional form of \code{:=} are interchangeable, there are some minor differences in the way that \code{RHS} is handled. In the functional form, \code{:=} operator behaves like an alias to \code{list}. This means that when \code{RHS} is a list, \code{LHS} is assigned a list. Avoid this by using the standard form when \code{RHS} is a list, or use a vector. See \href{../doc/datatable-reference-semantics.html}{\code{vignette("datatable-reference-semantics")}} for examples.
83
81
}
84
82
85
83
\section{Advanced (internals):}{It is easy to see how \emph{sub-assigning} to existing columns is done internally. Removing columns by reference is also straightforward by modifying the vector of column pointers only (using memmove in C). However adding (new) columns is more tricky as to how the \code{data.table} can be grown \emph{by reference}: the list vector of column pointers is \emph{over-allocated}, see \code{\link{truelength}}. By defining \code{:=} in \code{j} we believe update syntax is natural, and scales, but it also bypasses \code{[<-} dispatch and allows \code{:=} to update by reference with no copies of any part of memory at all.
Copy file name to clipboardExpand all lines: vignettes/datatable-reference-semantics.Rmd
-21Lines changed: 0 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -118,33 +118,12 @@ Note that the code above explains how `:=` can be used. They are not working exa
118
118
119
119
* On the other hand, (b) is handy if you would like to jot some comments down for later.
120
120
121
-
* In general, (a) and (b) should produce the same result, however there are minor differences in certain cases due to the implementation details of `:=`. Specifically, when using (b), the `:=` operator behaves like an alias to `list`, therefore if `RHS` is a `list` in functional form the column will become a list. See example below.
122
-
123
121
* The result is returned *invisibly*.
124
122
125
123
* Since `:=` is available in `j`, we can combine it with `i` and `by` operations just like the aggregation operations we saw in the previous vignette.
126
124
127
125
#
128
126
129
-
Although in most cases they are the same, there is a minor difference between the standard and functional forms mentioned above. Let's see an example to understand this.
130
-
```{r}
131
-
DT = data.table(a = list('A', 'B', 'C'))
132
-
l = list(1L:3L)
133
-
134
-
DT[, new_int := l] # Standard form, new column is integer
135
-
136
-
DT[, `:=`(new_list = l)] # Functional form, new column is a list of integer vectors
137
-
138
-
DT[, new_list := list(l)] # Same as above, we can see that `:=` is an alias to list in functional form
139
-
140
-
# This can be avoided by using a vector instead of a list:
141
-
v = 1L:3L
142
-
143
-
DT[, new_int := v] # Standard form, new column is integer
144
-
145
-
DT[, `:=`(new_int = v)] # Functional form, new column is integer
146
-
```
147
-
148
127
In the two forms of `:=` shown above, note that we don't assign the result back to a variable. Because we don't need to. The input *data.table* is modified by reference. Let's go through examples to understand what we mean by this.
149
128
150
129
For the rest of the vignette, we will work with `flights`*data.table*.
0 commit comments