Skip to content

Commit

Permalink
fix names_sd rev dep issue 6033 (#6238)
Browse files Browse the repository at this point in the history
* fix names_sd rev dev issue 6033

* Simplify test and improve comment about version

* remove trailing ws

* revdev->revdep

---------

Co-authored-by: Benjamin Schwendinger <benjaminschwe@gmail.com>
Co-authored-by: Michael Chirico <michaelchirico4@gmail.com>
Co-authored-by: Michael Chirico <chiricom@google.com>
  • Loading branch information
4 people authored Jul 13, 2024
1 parent 9e6ea19 commit e7e09d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
5 changes: 4 additions & 1 deletion inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit e7e09d8

Please sign in to comment.