ianmcook commented on a change in pull request #9798:
URL: https://github.com/apache/arrow/pull/9798#discussion_r602535771



##########
File path: r/tests/testthat/test-dplyr.R
##########
@@ -369,3 +384,46 @@ test_that("tail", {
       group_by(int)
     )
 })
+
+test_that("relocate", {
+  df <- tibble(a = 1, b = 1, c = 1, d = "a", e = "a", f = "a")
+  expect_dplyr_equal(
+    input %>% relocate(f) %>% collect(),
+    df,
+  )
+  expect_dplyr_equal(
+    input %>% relocate(a, .after = c) %>% collect(),
+    df,
+  )
+  expect_dplyr_equal(
+    input %>% relocate(f, .before = b) %>% collect(),
+    df,
+  )
+  expect_dplyr_equal(
+    input %>% relocate(a, .after = last_col()) %>% collect(),
+    df,
+  )
+  expect_dplyr_equal(
+    input %>% relocate(ff = f) %>% collect(),
+    df,
+  )
+})
+
+test_that("relocate with selection helpers", {
+  expect_dplyr_equal(
+    input %>% relocate(any_of(c("a", "e", "i", "o", "u"))) %>% collect(),
+    df
+  )
+  expect_error(
+    df %>% Table$create() %>% relocate(where(is.character)),

Review comment:
       Without `check_select_helpers()`, `relocate()` fails silently:
   ```r
   df <- tibble(a = 1, b = 1, c = 1, d = "a", e = "a", f = "a")
   df %>% Table$create() %>% relocate(where(is.numeric), .after = f)
   ## Table (query)
   ## a: double
   ## b: double
   ## c: double
   ## d: string
   ## e: string
   ## f: string
   ## 
   ## See $.data for the source Arrow object
   ```
   
   And here's how `select()` and `rename()` fail:
   ```r
   df <- tibble(a = 1, b = 1, c = 1, d = "a", e = "a", f = "a")
   df %>% Table$create() %>% select(where(is.numeric))
   ##  Error: This tidyselect interface doesn't support predicates yet.
   ## ℹ Contact the package author and suggest using `eval_select()`.
   ## Run `rlang::last_error()` to see where the error occurred. 
   ```
   I believe this error happens only because we're using questioning-stage 
rlang functions (`vars_select()` and `vars_rename()`) in our `column_select()` 
function and they don't support `where()`.




-- 
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.

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


Reply via email to