diff --git a/R/data.table.R b/R/data.table.R index 5d31cce54..133c987fe 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -1121,6 +1121,11 @@ replace_dot_alias = function(e) { if (is.name(lhs)) { lhs = as.character(lhs) } else { + #6033 revdep. Slowly deprecate in 1.17.0. Caller has given us `dt[, substitute(names(.SD))]` which means + # jsub is actually substitute(names(.SD)) instead of just names(.SD) + if (lhs %iscall% 'substitute') + lhs = eval(lhs, parent.frame(), parent.frame()) + # lhs is e.g. (MyVar) or get("MyVar") or names(.SD) || setdiff(names(.SD), cols) lhs = eval(lhs, list(.SD = setNames(logical(length(sdvars)), sdvars)), parent.frame()) } diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index d114d000c..b02063075 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -18383,10 +18383,13 @@ test(2250.11, dt[, names(.SD(2)) := lapply(.SD, .I)], error=base_messages$missin dt = data.table(a = 1:3, b = 5:7, grp = c('a', 'a', 'b')) test(2250.12, dt[, names(.SD) := lapply(.SD, function(x) x + b), .SDcols = "a"], data.table(a = 1:3 + 5:7, b = 5:7, grp = c('a', 'a', 'b'))) - dt = data.table(a = 1L, b = 2L, c = 3L, d = 4L, e = 5L, f = 6L) test(2250.13, dt[, names(.SD)[1:5] := sum(.SD)], data.table(a = 21L, b = 21L, c = 21L, d = 21L, e = 21L, f = 6L)) +dt = data.table(a = 1) #6033 revdep follow-up +my_col = "a" +test(2250.14, dt[, substitute(my_col) := .(3)], data.table(a = 3)) + # fread(...,fill) can also be used to specify a guess on the maximum number of columns #2691 #1812 #4130 #3436 #2727 dt_str = paste(rep(c("1,2\n", "1,2,3\n"), each=100), collapse="") ans = data.table(1L, 2L, rep(c(NA, 3L), each=100L))