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
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,6 +34,8 @@
34
34
35
35
5. Negative and missing values of `n` argument of adaptive rolling functions trigger an error.
36
36
37
+
6. `setDT()` and `setalloccol()` gain `duplicateShared` argument (default `TRUE`). When `TRUE`, columns that are shared with other objects are duplicated to avoid unintended modification of the original data, [#2683](https://github.com/Rdatatable/data.table/issues/2683). Previously, shared columns were not duplicated, which could lead to unexpected side effects. `frank()` now uses this internally to preserve names from the input vector and avoid modifying shared vectors, [#4240](https://github.com/Rdatatable/data.table/issues/4240). Thanks to @jangorecki, @BenoitLondon, and @MichaelChirico for the report and @ben-schwen for the fix.
38
+
37
39
### NOTICE OF INTENDED FUTURE POTENTIAL BREAKING CHANGES
38
40
39
41
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()`.
if (!selfrefok(x) || truelength(x) < ncol(x)+length(newnames)) {
2287
-
x= setalloccol(x, length(x)+length(newnames)) # because [<- copies via *tmp* and main/duplicate.c copies at length but copies truelength over too
2287
+
x= setalloccol(x, length(x)+length(newnames), duplicateShared=FALSE) # because [<- copies via *tmp* and main/duplicate.c copies at length but copies truelength over too
2288
2288
# search for one other .Call to assign in [.data.table to see how it differs
2289
2289
}
2290
2290
x= .Call(Cassign,copy(x),i,cols,newnames,value) # From 3.1.0, DF[2,"b"] = 7 no longer copies DF$a (so in this [<-.data.table method we need to copy)
2291
-
setalloccol(x) # can maybe avoid this realloc, but this is (slow) [<- anyway, so just be safe.
2291
+
setalloccol(x, duplicateShared=FALSE) # can maybe avoid this realloc, but this is (slow) [<- anyway, so just be safe.
2292
2292
if (length(reinstatekey)) setkeyv(x,reinstatekey)
2293
2293
invisible(x)
2294
2294
# no copy at all if user calls directly; i.e. `[<-.data.table`(x,i,j,value)
stopf("Cannot convert '%1$s' to data.table by reference because binding is locked. It is very likely that '%1$s' resides within a package (or an environment) that is locked to prevent modifying its variable bindings. Try copying the object to your current environment, ex: var <- copy(var) and then using setDT again.", cname)
2969
2969
}
2970
2970
}
2971
+
if (!isTRUEorFALSE(duplicateShared))
2972
+
stopf("'%s' must be TRUE or FALSE", "duplicateShared")
2971
2973
if (is.data.table(x)) {
2972
2974
# fix for #1078 and #1128, see .resetclass() for explanation.
2973
2975
setattr(x, 'class', .resetclass(x, 'data.table'))
2974
2976
if (!missing(key)) setkeyv(x, key) # fix for #1169
2975
2977
if (check.names) setattr(x, "names", make.names(names(x), unique=TRUE))
2976
-
if (selfrefok(x) >0L) return(invisible(x)) else setalloccol(x)
2978
+
if (selfrefok(x) >0L) return(invisible(x)) else setalloccol(x, duplicateShared=duplicateShared)
2977
2979
} elseif (is.data.frame(x)) {
2978
2980
# check no matrix-like columns, #3760. Allow a single list(matrix) is unambiguous and depended on by some revdeps, #3581
2979
2981
# for performance, only warn on the first such column, #5426
0 commit comments