Skip to content

Commit d8513e7

Browse files
committed
add fix to set
1 parent dc1dbe9 commit d8513e7

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

R/data.table.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,6 +2848,15 @@ setcolorder = function(x, neworder=key(x), before=NULL, after=NULL, skip_absent=
28482848

28492849
set = function(x,i=NULL,j,value) # low overhead, loopable
28502850
{
2851+
# If removing columns from a table that's not selfrefok, need to call setalloccol first, #7488
2852+
if (is.null(value) || (is.list(value) && any(vapply_1b(value, is.null)))) {
2853+
# Removing at least one column
2854+
ok = selfrefok(x, verbose=FALSE)
2855+
if (ok < 1L) {
2856+
# Table is not safe to resize (either fresh from disk or shallow copy)
2857+
setalloccol(x, n=eval(getOption("datatable.alloccol")), verbose=FALSE)
2858+
}
2859+
}
28512860
.Call(Cassign,x,i,j,NULL,value)
28522861
invisible(x)
28532862
}

inst/tests/tests.Rraw

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21898,7 +21898,8 @@ rm(DT, strings)
2189821898

2189921899
# do remove columns in freshly unserialized data.tables, #7488
2190021900
DT = unserialize(serialize(as.data.table(mtcars), NULL))
21901-
test(2351, DT[,carb:=NULL], as.data.table(mtcars)[,carb:=NULL])
21901+
test(2351.1, copy(DT)[,carb:=NULL], as.data.table(mtcars)[,carb:=NULL])
21902+
test(2351.2, set(copy(DT), j="carb", value=NULL), as.data.table(mtcars)[,carb:=NULL])
2190221903
rm(DT)
2190321904

2190421905
# rbindlist did not protect the temporary UTF-8 strings, #7452

0 commit comments

Comments
 (0)