From 135d2c1ab0e2966ac2fed129436ae1ee2582c2cd Mon Sep 17 00:00:00 2001 From: venom1204 Date: Fri, 20 Dec 2024 23:12:48 +0530 Subject: [PATCH 1/2] fixedd #6556 --- R/merge.R | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/R/merge.R b/R/merge.R index ab93d54983..758269a716 100644 --- a/R/merge.R +++ b/R/merge.R @@ -35,10 +35,14 @@ merge.data.table = function(x, y, by = NULL, by.x = NULL, by.y = NULL, all = FAL if (!is.null(by.x)) { 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.") - if (!all(by.y %chin% nm_y)) - stopf("Elements listed in `by.y` must be valid column names in y.") + if (!all(by.x %chin% nm_x)) { + missing_by_x = setdiff(by.x, nm_x) + stopf("Elements listed in `by.x` must be valid column names in x. Missing: %s", paste(missing_by_x, collapse = ", ")) + } + if (!all(by.y %chin% nm_y)) { + missing_by_y = setdiff(by.y, nm_y) + stopf("Elements listed in `by.y` must be valid column names in y. Missing: %s", paste(missing_by_y, collapse = ", ")) + } by = by.x names(by) = by.y } else { @@ -50,8 +54,12 @@ 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") + if (!all(by %chin% intersect(nm_x, nm_y))) { + missing_in_x = setdiff(by, nm_x) + missing_in_y = setdiff(by, nm_y) + stopf("Elements listed in `by` must be valid column names in x and y. Missing in x: %s. Missing in y: %s", + paste(missing_in_x, collapse = ", "), paste(missing_in_y, collapse = ", ")) + } by = unname(by) by.x = by.y = by } From 1abfa3410f8c95a3172186b3fb530c6eade313c3 Mon Sep 17 00:00:00 2001 From: venom1204 Date: Fri, 20 Dec 2024 23:31:03 +0530 Subject: [PATCH 2/2] final --- R/merge.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/merge.R b/R/merge.R index 758269a716..18512728d5 100644 --- a/R/merge.R +++ b/R/merge.R @@ -37,11 +37,11 @@ merge.data.table = function(x, y, by = NULL, by.x = NULL, by.y = NULL, all = FAL stopf("A non-empty vector of column names is required for `by.x` and `by.y`.") if (!all(by.x %chin% nm_x)) { missing_by_x = setdiff(by.x, nm_x) - stopf("Elements listed in `by.x` must be valid column names in x. Missing: %s", paste(missing_by_x, collapse = ", ")) + stopf("Elements listed in `by.x` must be valid column names in x. Missing: %s", toString(missing_by_x)) # changed here } if (!all(by.y %chin% nm_y)) { missing_by_y = setdiff(by.y, nm_y) - stopf("Elements listed in `by.y` must be valid column names in y. Missing: %s", paste(missing_by_y, collapse = ", ")) + stopf("Elements listed in `by.y` must be valid column names in y. Missing: %s", toString(missing_by_y)) # changed here } by = by.x names(by) = by.y @@ -58,7 +58,7 @@ merge.data.table = function(x, y, by = NULL, by.x = NULL, by.y = NULL, all = FAL missing_in_x = setdiff(by, nm_x) missing_in_y = setdiff(by, nm_y) stopf("Elements listed in `by` must be valid column names in x and y. Missing in x: %s. Missing in y: %s", - paste(missing_in_x, collapse = ", "), paste(missing_in_y, collapse = ", ")) + toString(missing_in_x), toString(missing_in_y)) # changed here } by = unname(by) by.x = by.y = by