-
Notifications
You must be signed in to change notification settings - Fork 1k
feat : added condition to check the RHS of := #7161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1411,7 +1411,13 @@ replace_dot_alias = function(e) { | |
} | ||
|
||
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)) | ||
if (length(newnames) > 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this error not happen for the case of overwriting an existing column? |
||
if (is.function(jval)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this will catch the following case (which you should add as a new regression test): DT=data.table(a=1:10)
DT[,c('a', 'b'):=.(1:10, mean)] |
||
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)) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference between this assignment and the one above?
data.table/R/data.table.R
Line 1218 in 2f0d12f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both compute setdiff(lhs, names(x)), but the one above uses the cached names_x. I’ll update the later one to use names_x as well for consistency and to avoid unnecessary recomputation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry i don't understand, why recalculate
newnames
at all if it's just the same value as above?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thanks. The second newnames assignment was redundant. I will take care of it.