-
Notifications
You must be signed in to change notification settings - Fork 991
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
closes #6556 [feature request] diagnostic for merge.data.table when by = key is not present in dt being merged #6691
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 |
---|---|---|
|
@@ -50,11 +50,30 @@ merge.data.table = function(x, y, by = NULL, by.x = NULL, by.y = NULL, all = FAL | |
by = intersect(nm_x, nm_y) | ||
if (length(by) == 0L || !is.character(by)) | ||
stopf("A non-empty vector of column names for `by` is required.") | ||
if (!all(by %chin% intersect(nm_x, nm_y))) | ||
stopf("Elements listed in `by` must be valid column names in x and y") | ||
by = unname(by) | ||
by.x = by.y = by | ||
# UPDATED PART STARTS HERE | ||
if (!all(by %chin% intersect(nm_x, nm_y))) { | ||
# Identify which keys are missing from each data table | ||
missing_x = setdiff(by, nm_x) | ||
missing_y = setdiff(by, nm_y) | ||
|
||
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. @venom1204, do you see a "check warning" from the "lint-r" check around this line when you visit the files changed tab of the pull request? It is asking you to remove the spaces on line 58. Since it doesn't contain any text, it shouldn't contain any spaces either. |
||
# Construct a more detailed error message | ||
error_message = "Elements listed in `by` must be valid column names in x and y." | ||
|
||
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. Also remove the spaces at the beginning of the line 61. |
||
if (length(missing_x) > 0) { | ||
error_message = paste(error_message, "\nMissing columns in 'x':", paste(missing_x, collapse = ", ")) | ||
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. Here, lint-r is asking you to use |
||
} | ||
if (length(missing_y) > 0) { | ||
error_message = paste(error_message, "\nMissing columns in 'y':", paste(missing_y, collapse = ", ")) | ||
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. Same as above. |
||
} | ||
|
||
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. Again some spaces at the beginning of the line. |
||
# Raise the error with the detailed message | ||
stopf(error_message) | ||
} | ||
# UPDATED PART ENDS HERE | ||
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. Since you are using a version control system, there is no need to delimit the updated part using comments. The difference between the original code and your change request can be reliably computed by Git itself. |
||
|
||
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. Again spaces on the otherwise empty line. |
||
by = unname(by) | ||
by.x = by.y = by | ||
} | ||
|
||
# warn about unused arguments #2587 | ||
if (length(list(...))) { | ||
|
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 comment will stop being helpful after the suggested change is accepted, and we have more reliable ways of finding out which parts of the code are updated.