You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/03/22 14:36:09 UTC

[GitHub] [arrow] thisisnic commented on a change in pull request #12642: ARROW-15947: [R] rename_with s3 method for arrow_dplyr_query

thisisnic commented on a change in pull request #12642:
URL: https://github.com/apache/arrow/pull/12642#discussion_r832249136



##########
File path: r/R/dplyr-select.R
##########
@@ -32,6 +32,16 @@ rename.arrow_dplyr_query <- function(.data, ...) {
 }
 rename.Dataset <- rename.ArrowTabular <- rename.RecordBatchReader <- rename.arrow_dplyr_query
 
+rename_with.arrow_dplyr_query <- function(.data, .fn, .cols = everything(), ...) {
+  .fn <- rlang::as_function(.fn)

Review comment:
       In `arrow/r/R/arrow-package-R` we have a load of `rlang` function listed with `@importFrom` roxygen tags.  Could you add `as_function` there and then call it directly here?

##########
File path: r/R/dplyr-select.R
##########
@@ -32,6 +32,16 @@ rename.arrow_dplyr_query <- function(.data, ...) {
 }
 rename.Dataset <- rename.ArrowTabular <- rename.RecordBatchReader <- rename.arrow_dplyr_query
 
+rename_with.arrow_dplyr_query <- function(.data, .fn, .cols = everything(), ...) {
+  .fn <- rlang::as_function(.fn)
+  old_names <- names(select(.data, {{ .cols }}))
+  new_names <- do.call(.fn, list(old_names))

Review comment:
       Let's remove the `do.call()` here.  Perhaps `.fn(old_names)` could work?

##########
File path: r/R/dplyr-select.R
##########
@@ -32,6 +32,16 @@ rename.arrow_dplyr_query <- function(.data, ...) {
 }
 rename.Dataset <- rename.ArrowTabular <- rename.RecordBatchReader <- rename.arrow_dplyr_query
 
+rename_with.arrow_dplyr_query <- function(.data, .fn, .cols = everything(), ...) {
+  .fn <- rlang::as_function(.fn)
+  old_names <- names(select(.data, {{ .cols }}))
+  new_names <- do.call(.fn, list(old_names))
+  rename_args <- c(list(.data), as.list(old_names))
+  names(rename_args) <- c(".data", new_names)
+  do.call(rename, rename_args)

Review comment:
       ```suggestion
     rename(.data, !!set_names(old_names, new_names))
   ```
   Minor change here to make this more `rlang` style in keeping with the other code in the package.




-- 
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-unsubscribe@arrow.apache.org

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