Skip to content

Commit

Permalink
more verbose merge errors
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleHaynes committed Dec 23, 2024
1 parent e4b0bbb commit e8c9fe8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions R/merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,15 @@ merge.data.table = function(x, y, by = NULL, by.x = NULL, by.y = NULL, all = FAL
if (length(by.x)==0L || !is.character(by.x) || !is.character(by.y))
stopf("A non-empty vector of column names is required for `by.x` and `by.y`.")
if (!all(by.x %chin% nm_x))
stopf("Elements listed in `by.x` must be valid column names in x.")
stopf(paste(
"Elements listed in `by.x` must be valid column names in x.",
"\n Missing from `x`:", paste(setdiff(by.x, nm_x), collapse = ", ")

Check warning on line 41 in R/merge.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/merge.R,line=41,col=34,[paste_linter] toString(.) is more expressive than paste(., collapse = ", "). Note also glue::glue_collapse() and and::and() for constructing human-readable / translation-friendly lists
))
if (!all(by.y %chin% nm_y))
stopf("Elements listed in `by.y` must be valid column names in y.")
stopf(paste(
"Elements listed in `by.y` must be valid column names in y.",
"\n Missing from `y`:", paste(setdiff(by.y, nm_y), collapse = ", ")

Check warning on line 46 in R/merge.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/merge.R,line=46,col=34,[paste_linter] toString(.) is more expressive than paste(., collapse = ", "). Note also glue::glue_collapse() and and::and() for constructing human-readable / translation-friendly lists
))
by = by.x
names(by) = by.y
} else {
Expand All @@ -51,7 +57,13 @@ merge.data.table = function(x, y, by = NULL, by.x = NULL, by.y = NULL, all = FAL
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")
stopf(
paste(
"Elements listed in `by` must be valid column names in x and y.",
if(length(setdiff(by, nm_x)) > 0) "\n Missing from `x`:", paste(setdiff(by, nm_x), collapse = ", "),

Check warning on line 63 in R/merge.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/merge.R,line=63,col=70,[paste_linter] toString(.) is more expressive than paste(., collapse = ", "). Note also glue::glue_collapse() and and::and() for constructing human-readable / translation-friendly lists
if(length(setdiff(by, nm_y)) > 0) "\n Missing from `y`:", paste(setdiff(by, nm_y), collapse = ", ")

Check warning on line 64 in R/merge.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/merge.R,line=64,col=70,[paste_linter] toString(.) is more expressive than paste(., collapse = ", "). Note also glue::glue_collapse() and and::and() for constructing human-readable / translation-friendly lists
)
)
by = unname(by)
by.x = by.y = by
}
Expand Down

0 comments on commit e8c9fe8

Please sign in to comment.