-
Notifications
You must be signed in to change notification settings - Fork 998
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
feat : added condition to check the RHS of := #6742
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6742 +/- ##
==========================================
- Coverage 98.62% 98.62% -0.01%
==========================================
Files 79 79
Lines 14645 14647 +2
==========================================
+ Hits 14444 14445 +1
- Misses 201 202 +1 ☔ View full report in Codecov by Sentry. |
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.
also please add test cases based on my issue
@@ -316,6 +316,9 @@ replace_dot_alias = function(e) { | |||
warningf("nomatch isn't relevant together with :=, ignoring nomatch") | |||
nomatch=NULL | |||
} | |||
if (length(jsub) >= 3L && is.function(jsub[[3L]])) { | |||
stopf("the right hand side of := should be a vector, list, data.frame, function or call, not a function,to store a function wrap it in a list: DT[, newcol := list(myfun)]") |
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.
this is self-contradictory "should be a ...function or call, not a function..." please clarify/fix.
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.
The actual error message will be:
"The right-hand side of := should be a vector, list, or data.frame, not a function. To store a function, wrap it in a list: DT[, newcol := list(myfun)]"
Can you confirm if this implementation is correct? When I run the test to check it, the following error is displayed:
Test 2306.2 produced 1 errors but expected 0
Expected:
Observed: invalid type/length (closure/3) in vector allocation
This error is for the test:
Edit
DT = data.table(x = 1:3)
test(2306.2, DT[, y := list(mean)], data.table(x = 1:3, y = list(mean, mean, mean)))
I cannot figure out where this observed error is coming from.
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.
if (length(jsub) >= 3L && is.function(jsub[[3L]])) {
stopf("the right hand side of := should be a vector, list, data.frame, or function call. To store a raw function, wrap it in a list: DT[, newcol := list(myfun)]")
}
the intent should be:
- Raw functions shouldn't be assigned directly as column values
- Functions should be wrapped in a list when being assigned
- Function calls (like mean(x)) are allowed
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.
@venom1204 fix at your own convenience
Closes #5829.
I have added a condition to validate the right-hand side (RHS) of the := operator. If the RHS is a standalone function, an error is raised with an informative message guiding the user to wrap the function in a list if it is intended to be stored.
@tdhock, could you please review this and let me know for further improvements or additional scenarios that I should do?thank you.