nealrichardson commented on code in PR #41576:
URL: https://github.com/apache/arrow/pull/41576#discussion_r1616406089


##########
r/R/dplyr-mutate.R:
##########
@@ -24,122 +24,116 @@ mutate.arrow_dplyr_query <- function(.data,
                                      .keep = c("all", "used", "unused", 
"none"),
                                      .before = NULL,
                                      .after = NULL) {
-  call <- match.call()
-  out <- as_adq(.data)
+  try_arrow_dplyr({
+    out <- as_adq(.data)
 
-  by <- compute_by({{ .by }}, out, by_arg = ".by", data_arg = ".data")
+    by <- compute_by({{ .by }}, out, by_arg = ".by", data_arg = ".data")
 
-  if (by$from_by) {
-    out$group_by_vars <- by$names
-  }
-  grv <- out$group_by_vars
-  expression_list <- expand_across(out, quos(...), exclude_cols = grv)
-  exprs <- ensure_named_exprs(expression_list)
+    if (by$from_by) {
+      out$group_by_vars <- by$names
+    }
+    grv <- out$group_by_vars
+    expression_list <- expand_across(out, quos(...), exclude_cols = grv)
+    exprs <- ensure_named_exprs(expression_list)
 
-  .keep <- match.arg(.keep)
-  .before <- enquo(.before)
-  .after <- enquo(.after)
+    .keep <- match.arg(.keep)
+    .before <- enquo(.before)
+    .after <- enquo(.after)
 
-  if (.keep %in% c("all", "unused") && length(exprs) == 0) {
-    # Nothing to do
-    return(out)
-  }
+    if (.keep %in% c("all", "unused") && length(exprs) == 0) {
+      # Nothing to do
+      return(out)
+    }
 
-  # Create a mask with aggregation functions in it
-  # If there are any aggregations, we will need to compute them and
-  # and join the results back in, for "window functions" like x - mean(x)
-  mask <- arrow_mask(out)
-  # Evaluate the mutate expressions
-  results <- list()
-  for (i in seq_along(exprs)) {
-    # Iterate over the indices and not the names because names may be repeated
-    # (which overwrites the previous name)
-    new_var <- names(exprs)[i]
-    results[[new_var]] <- arrow_eval(exprs[[i]], mask)
-    if (inherits(results[[new_var]], "try-error")) {
-      msg <- handle_arrow_not_supported(
-        results[[new_var]],
-        format_expr(exprs[[i]])
-      )
-      return(abandon_ship(call, .data, msg))
-    } else if (!inherits(results[[new_var]], "Expression") &&
-      !is.null(results[[new_var]])) {
-      # We need some wrapping to handle literal values
-      if (length(results[[new_var]]) != 1) {
-        msg <- paste0("In ", new_var, " = ", format_expr(exprs[[i]]), ", only 
values of size one are recycled")
-        return(abandon_ship(call, .data, msg))
+    # Create a mask with aggregation functions in it
+    # If there are any aggregations, we will need to compute them and
+    # and join the results back in, for "window functions" like x - mean(x)
+    mask <- arrow_mask(out)
+    # Evaluate the mutate expressions
+    results <- list()
+    for (i in seq_along(exprs)) {
+      # Iterate over the indices and not the names because names may be 
repeated
+      # (which overwrites the previous name)
+      new_var <- names(exprs)[i]
+      results[[new_var]] <- arrow_eval(exprs[[i]], mask)
+      if (!inherits(results[[new_var]], "Expression") &&
+        !is.null(results[[new_var]])) {
+        # We need some wrapping to handle literal values
+        if (length(results[[new_var]]) != 1) {
+          arrow_not_supported("Recycling values of length != 1", call = 
exprs[[i]])

Review Comment:
   Here's another not-just-indentation change: for validations/errors outside 
of arrow_eval, we just raise `arrow_not_supported` or `validation_error` like 
in the function bindings. 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to