Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -2848,6 +2848,14 @@ setcolorder = function(x, neworder=key(x), before=NULL, after=NULL, skip_absent=

set = function(x,i=NULL,j,value) # low overhead, loopable
{
# If removing columns from a table that's not selfrefok, need to call setalloccol first, #7488
if ((is.null(value) || (is.list(value) && any(vapply_1b(value, is.null)))) && selfrefok(x, verbose=FALSE) < 1L) {
name = substitute(x)
setalloccol(x, verbose=FALSE)
if (is.name(name)) {
assign(as.character(name), x, parent.frame(), inherits=TRUE)
}
}
.Call(Cassign,x,i,j,NULL,value)
invisible(x)
}
Expand Down
9 changes: 8 additions & 1 deletion inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -21898,7 +21898,14 @@ rm(DT, strings)

# do remove columns in freshly unserialized data.tables, #7488
DT = unserialize(serialize(as.data.table(mtcars), NULL))
test(2351, DT[,carb:=NULL], as.data.table(mtcars)[,carb:=NULL])
test(2351.1, DT[,carb:=NULL], as.data.table(mtcars)[,carb:=NULL])
DT = unserialize(serialize(as.data.table(mtcars), NULL))
test(2351.2, set(DT, j="carb", value=NULL), as.data.table(mtcars)[,carb:=NULL])
DT = unserialize(serialize(as.data.table(mtcars), NULL))
null_in_value <- NULL
test(2351.3, "cyl" %notin% names(DT[, cyl := null_in_value]))
DT = unserialize(serialize(as.data.table(mtcars), NULL))
test(2351.4, ncol(DT[, c("cyl", "mpg") := .(null_in_value, null_in_value)]), ncol(mtcars) - 2L)
rm(DT)

# rbindlist did not protect the temporary UTF-8 strings, #7452
Expand Down
Loading