thisisnic commented on code in PR #13786: URL: https://github.com/apache/arrow/pull/13786#discussion_r945659781
########## r/R/dplyr-mutate.R: ########## @@ -151,3 +153,95 @@ ensure_named_exprs <- function(exprs) { names(exprs)[unnamed] <- map_chr(exprs[unnamed], format_expr) exprs } + +# Take the input quos and unfold any instances of across() +# into individual quosures +unfold_across <- function(.data, quos_in) { + quos_out <- list() + # Check for any expressions starting with across + for (quo_i in seq_along(quos_in)) { + quo_in <- quos_in[quo_i] + quo_expr <- quo_get_expr(quo_in[[1]]) + + if (is_call(quo_expr, "across")) { + new_quos <- list() + across_call <- match.call(dplyr::across, quo_expr) + + if (!all(names(across_call[-1]) %in% c(".cols", ".fns", ".names"))) { + abort("`...` argument to `across()` is deprecated in dplyr and not supported in Arrow") + } + + # ARROW-17364: add support for .names argument + if (!is.null(across_call[[".names"]])) { + abort("`.names` argument to `across()` not yet supported in Arrow") + } + + # use select() to get the column names so we can take advantage of tidyselect + cols <- names(select(.data, !!across_call[[".cols"]])) + funcs <- as.character(across_call[[".fns"]]) + + # calling across() with .fns = NULL returns all columns unchanged + if (is_empty(funcs)) { + return() + } + + if (funcs[[1]] == "~") { + abort( + paste( + "purrr-style lambda functions as `.fns` argument to `across()`", + "not yet supported in Arrow" + ) + ) + } + + # if only 1 function, we overwrite the old columns with the new values + if (length(funcs) == 1) { + # work out the quosures from the call + col_syms <- syms(cols) + new_quos <- map(col_syms, ~ quo(!!call2(funcs, .x))) + new_quos <- set_names(new_quos, cols) + } else { + # remove `c()` and `list()` which have been used to specify functions + extracted_funcs <- funcs[map_lgl(funcs, ~ !.x %in% c("c", "list"))] + + func_list <- ensure_named_funcs(extracted_funcs) + new_quos <- quosures_from_func_list(func_list, cols) + } + + quos_out <- append(quos_out, new_quos) Review Comment: Agreed, updated now. -- 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