Skip to content

Commit 931e8e2

Browse files
authored
handle subexpressions for set delete (#7508)
1 parent ba7a1b3 commit 931e8e2

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

R/data.table.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,6 +2862,9 @@ set = function(x,i=NULL,j,value) # low overhead, loopable
28622862
setalloccol(x, verbose=FALSE)
28632863
if (is.name(name)) {
28642864
assign(as.character(name), x, parent.frame(), inherits=TRUE)
2865+
} else if (is.call(name)) {
2866+
# handle subexpressions like self$dt, foo[["bar"]], etc. by evaluating the assignment in parent frame
2867+
eval(call("<-", name, x), parent.frame())
28652868
}
28662869
}
28672870
.Call(Cassign,x,i,j,NULL,value)

inst/tests/tests.Rraw

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21906,7 +21906,13 @@ null_in_value <- NULL
2190621906
test(2351.3, "cyl" %notin% names(DT[, cyl := null_in_value]))
2190721907
DT = unserialize(serialize(as.data.table(mtcars), NULL))
2190821908
test(2351.4, ncol(DT[, c("cyl", "mpg") := .(null_in_value, null_in_value)]), ncol(mtcars) - 2L)
21909-
rm(DT)
21909+
l = list(DT = unserialize(serialize(as.data.table(mtcars), NULL)))
21910+
test(2351.5, set(l$DT, j="carb", value=NULL), as.data.table(mtcars)[,carb:=NULL])
21911+
test(2351.6, "carb" %notin% names(l$DT))
21912+
l = list(DT = unserialize(serialize(as.data.table(mtcars), NULL)))
21913+
test(2351.7, set(l[["DT"]], j="carb", value=NULL), as.data.table(mtcars)[,carb:=NULL])
21914+
test(2351.8, "carb" %notin% names(l$DT))
21915+
rm(DT, l)
2191021916

2191121917
# rbindlist did not protect the temporary UTF-8 strings, #7452
2191221918
DTn = apply(matrix(as.raw(rep(0xa1:0xff, length.out = 100)), 10), 2, rawToChar)

0 commit comments

Comments
 (0)