Skip to content
9 changes: 8 additions & 1 deletion R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,14 @@
}

if (!is.null(lhs)) {
# TODO?: use set() here now that it can add new columns. Then remove newnames and alloc logic above.
newnames = setdiff(lhs, names(x))

Check warning on line 1407 in R/data.table.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/data.table.R,line=1407,col=1,[trailing_whitespace_linter] Remove trailing whitespace.
if (length(newnames) > 0) {
if (is.function(jval)) {
stopf("RHS of `:=` is a function. To create a new column of functions, it must be a list column (e.g., wrap the function in `list()`).")
}
}
# TODO?: use set() here now that it can add new columns.Then remove newnames and alloc logic above.
.Call(Cassign,x,irows,cols,newnames,jval)
return(suppPrint(x))
}
Expand Down
5 changes: 5 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -21157,3 +21157,8 @@ test(2317.6, DT1[DF1, on='a', .(d = x.a + i.d)]$d, 5)
test(2317.7, DT1[DF2, on='a', e := i.e]$e, 5)
test(2317.8, DT1[DF2, on='a', e2 := x.a + i.e]$e2, 6)
test(2317.9, DT1[DF2, on='a', .(e = x.a + i.e)]$e, 6)

DT = data.table(x = 1:3)

test(2318.1, DT[, y := mean], error = "RHS of `:=` is a function")
test(2318.2, DT[, y := function(x) x], error = "RHS of `:=` is a function")
Loading