dragosmg commented on a change in pull request #12179:
URL: https://github.com/apache/arrow/pull/12179#discussion_r787564893



##########
File path: r/R/dplyr-join.R
##########
@@ -117,10 +117,33 @@ handle_join_by <- function(by, x, y) {
   if (is.null(names(by))) {
     by <- set_names(by)
   }
-  # TODO: nicer messages?
-  stopifnot(
-    all(names(by) %in% names(x)),
-    all(by %in% names(y))
-  )
+
+  missing_x_cols <- setdiff(names(by), names(x))
+  if (length(missing_x_cols) > 0) {
+    message <- paste(
+      "Join",
+      ngettext(length(missing_x_cols), "column", "columns"),
+      "must be present in data."
+    )
+    message_x <- paste(
+      oxford_paste(missing_x_cols, quote_symbol = "`"),
+      "not present in x."
+      )
+    abort(c(message, x = message_x))
+  }
+
+  missing_y_cols <- setdiff(by, names(y))
+  if (length(missing_y_cols) > 0) {
+    message <- paste(
+      "Join",
+      ngettext(length(missing_y_cols), "column", "columns"),
+      "must be present in data."
+    )
+    message_y <- paste(
+      oxford_paste(missing_y_cols, quote_symbol = "`"),
+      "not present in y."
+    )
+    abort(c(message, x = message_y))
+  }

Review comment:
       Done
   ```
   > left_join(
   +         arrow_table(example_data),
   +         arrow_table(example_data),
   +         by = c("made_up_colname1", "made_up_colname2")
   +       )
    Error: Join columns must be present in data.
   x `made_up_colname1` and `made_up_colname2` not present in x.
   x `made_up_colname1` and `made_up_colname2` not present in y.
   Run `rlang::last_error()` to see where the error occurred.
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to