Skip to content

Commit 49c52d0

Browse files
committed
added condition to check the rhs
1 parent 5bbc4d5 commit 49c52d0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

R/data.table.R

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

14051405
if (!is.null(lhs)) {
1406+
# We only need to check if we are creating new columns.
1407+
newnames = setdiff(lhs, names(x))
1408+
1409+
if (length(newnames) > 0) {
1410+
if (is.function(jval)) {
1411+
stopf("RHS of `:=` is a function. To create a new column of functions, it must be a list column (e.g., wrap in `list()`).")
1412+
} else if (is.list(jval) && length(jval) == 1 && is.function(jval[[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)` or `list(replicate(.N, myfun))` to match the number of rows.")
1414+
}
1415+
}
14061416
# TODO?: use set() here now that it can add new columns. Then remove newnames and alloc logic above.
14071417
.Call(Cassign,x,irows,cols,newnames,jval)
14081418
return(suppPrint(x))

0 commit comments

Comments
 (0)