From 89a22b3f8286e8211e8058a9630840a117f3e249 Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Wed, 10 Jul 2024 21:44:54 -0400 Subject: [PATCH 1/4] fix names_sd rev dev issue 6033 --- R/data.table.R | 5 +++++ inst/tests/tests.Rraw | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/R/data.table.R b/R/data.table.R index 0f3b766160..d80cf67edc 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -1122,6 +1122,11 @@ replace_dot_alias = function(e) { if (is.name(lhs)) { lhs = as.character(lhs) } else { + #6033 revdev. Slowly deprecate in 1.17. 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 16161f974f..e31a2622b4 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -18393,10 +18393,12 @@ 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:4, b = 5:8) #6033 revdev follow-up +test(2250.14, dt[, substitute(names(.SD)) := lapply(.SD, `*`, 2), .SDcols = 1L], data.table(a = 1:4 * 2, b = 5:8)) + # 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)) From ba6b70eaca38f64fd338053e2e8a1685456906db Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Wed, 10 Jul 2024 22:13:32 -0400 Subject: [PATCH 2/4] Simplify test and improve comment about version --- R/data.table.R | 2 +- inst/tests/tests.Rraw | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/R/data.table.R b/R/data.table.R index d80cf67edc..143537b1ec 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -1122,7 +1122,7 @@ replace_dot_alias = function(e) { if (is.name(lhs)) { lhs = as.character(lhs) } else { - #6033 revdev. Slowly deprecate in 1.17. Caller has given us `dt[, substitute(names(.SD))]` which means + #6033 revdev. 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()) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index e31a2622b4..c7bebaaf55 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -18396,8 +18396,9 @@ test(2250.12, dt[, names(.SD) := lapply(.SD, function(x) x + b), .SDcols = "a"], 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:4, b = 5:8) #6033 revdev follow-up -test(2250.14, dt[, substitute(names(.SD)) := lapply(.SD, `*`, 2), .SDcols = 1L], data.table(a = 1:4 * 2, b = 5:8)) +dt = data.table(a = 1) #6033 revdev 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="") From d6d3d84742976f6b13a5ae0e5dd67a04a80e2dc4 Mon Sep 17 00:00:00 2001 From: Benjamin Schwendinger Date: Thu, 11 Jul 2024 13:24:30 +0200 Subject: [PATCH 3/4] remove trailing ws --- R/data.table.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/data.table.R b/R/data.table.R index 143537b1ec..aeadcc851d 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -1122,9 +1122,9 @@ replace_dot_alias = function(e) { if (is.name(lhs)) { lhs = as.character(lhs) } else { - #6033 revdev. Slowly deprecate in 1.17.0. Caller has given us `dt[, substitute(names(.SD))]` which means + #6033 revdev. 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') + 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) From 1024792cad8fe2dd344ee3aa7f9ddb02980d4c8b Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Fri, 12 Jul 2024 13:42:55 -0700 Subject: [PATCH 4/4] revdev->revdep --- R/data.table.R | 2 +- inst/tests/tests.Rraw | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/data.table.R b/R/data.table.R index f1575c4ecb..133c987fe9 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -1121,7 +1121,7 @@ replace_dot_alias = function(e) { if (is.name(lhs)) { lhs = as.character(lhs) } else { - #6033 revdev. Slowly deprecate in 1.17.0. Caller has given us `dt[, substitute(names(.SD))]` which means + #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()) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 50e6ec1118..b020630757 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -18386,7 +18386,7 @@ test(2250.12, dt[, names(.SD) := lapply(.SD, function(x) x + b), .SDcols = "a"], 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 revdev follow-up +dt = data.table(a = 1) #6033 revdep follow-up my_col = "a" test(2250.14, dt[, substitute(my_col) := .(3)], data.table(a = 3))