From 05f7b6ca52e36b1455ad3cc3dae288388cbe8cf8 Mon Sep 17 00:00:00 2001 From: venom1204 Date: Fri, 20 Dec 2024 22:00:41 +0530 Subject: [PATCH 1/2] #6665_fixed --- man/setkey.Rd | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/man/setkey.Rd b/man/setkey.Rd index 378f1a106a..7446d07366 100644 --- a/man/setkey.Rd +++ b/man/setkey.Rd @@ -116,6 +116,16 @@ reference. \examples{ # Type 'example(setkey)' to run these at the prompt and browse output +# Example: Single character vector of column names +DT = data.table(A = 5:1, B = letters[5:1], C = 10:6) +setindex(DT, A) # Set index using a single column +indices(DT) # View the indices + +# Example: List of character vectors +setindexv(DT, list(c("A", "B"), c("B", "C"))) # Setting multiple indices +indices(DT) # View all indices +indices(DT, vectors = TRUE) # View indices as a list of vectors + DT = data.table(A=5:1,B=letters[5:1]) DT # before setkey(DT,B) # re-orders table and marks it sorted. From e34ceb63573ee9821f5a92a09585dd430d2ca02f Mon Sep 17 00:00:00 2001 From: venom1204 Date: Sat, 21 Dec 2024 01:07:59 +0530 Subject: [PATCH 2/2] fixed #6556 --- R/merge.R | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/R/merge.R b/R/merge.R index ab93d54983..18512728d5 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", 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", toString(missing_by_y)) # changed here + } 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", + toString(missing_in_x), toString(missing_in_y)) # changed here + } by = unname(by) by.x = by.y = by }