Skip to content

Commit b295e9b

Browse files
committed
removed the list check
1 parent 3fe9173 commit b295e9b

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

R/data.table.R

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,18 +1403,13 @@ replace_dot_alias = function(e) {
14031403
}
14041404

14051405
if (!is.null(lhs)) {
1406-
if (length(cols) == 1L) {
1407-
is_new_col <- cols > ncol(x)
1408-
if (is_new_col || !is.list(x[[cols]])) {
1409-
if (is.function(jval)) {
1410-
stopf("RHS of `:=` is a function. To create a new column of functions or assign to a non-list-column, it must be wrapped in a list(), e.g., `:= list(myfun)`.")
1411-
}
1412-
if (is.list(jval) && length(jval) == 1L && is.function(jval[[1L]]) && nrow(x) > 1L) {
1413-
stopf("RHS of `:=` is a length-1 list containing a function. `data.table` does not automatically recycle lists. To create a list-column, use `rep(list(myfun), .N)`.")
1414-
}
1406+
newnames = setdiff(lhs, names(x))
1407+
1408+
if (length(newnames) > 0) {
1409+
if (is.function(jval)) {
1410+
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()`).")
14151411
}
14161412
}
1417-
newnames = setdiff(lhs, names(x))
14181413
# TODO?: use set() here now that it can add new columns.Then remove newnames and alloc logic above.
14191414
.Call(Cassign,x,irows,cols,newnames,jval)
14201415
return(suppPrint(x))

inst/tests/tests.Rraw

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21161,9 +21161,4 @@ test(2317.9, DT1[DF2, on='a', .(e = x.a + i.e)]$e, 6)
2116121161
DT = data.table(x = 1:3)
2116221162

2116321163
test(2318.1, DT[, y := mean], error = "RHS of `:=` is a function")
21164-
test(2318.2, DT[, y := list(mean)], error = "RHS of `:=` is a length-1 list containing a function")
21165-
f = mean
21166-
test(2318.3, DT[, y := f], error = "RHS of `:=` is a function")
21167-
test(2318.4, DT[, y := identity(mean)], error = "RHS of `:=` is a function")
21168-
test(2318.5, data.table(x = 1)[, y := mean], error = "RHS of `:=` is a function")
21169-
test(2318.6, data.table(x = 1:2)[, y := mean], error = "RHS of `:=` is a function")
21164+
test(2318.2, DT[, y := function(x) x], error = "RHS of `:=` is a function")

0 commit comments

Comments
 (0)