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 2021/07/17 18:18:46 UTC

[GitHub] [arrow] nealrichardson commented on a change in pull request #10737: ARROW-13200: [R] Add binding for case_when()

nealrichardson commented on a change in pull request #10737:
URL: https://github.com/apache/arrow/pull/10737#discussion_r671727895



##########
File path: r/R/dplyr-functions.R
##########
@@ -651,3 +651,47 @@ nse_funcs$log <- function(x, base = exp(1)) {
 }
 
 nse_funcs$logb <- nse_funcs$log
+
+nse_funcs$case_when <- function(...) {
+  formulas <- list2(...)
+  n <- length(formulas)
+  if (n == 0) {
+    abort("No cases provided in case_when()")
+  }
+  query <- vector("list", n)
+  value <- vector("list", n)
+  mask <- caller_env()
+  for (i in seq_len(n)) {
+    f <- formulas[[i]]
+    if (!inherits(f, "formula")) {
+      abort("Each argument to case_when() must be a two-sided formula")
+    }
+    query[[i]] <- arrow_eval(f[[2]], mask)
+    value[[i]] <- arrow_eval(f[[3]], mask)
+    if (!nse_funcs$is.logical(query[[i]])) {
+      abort("Left side of each formula in case_when() must be a logical expression")
+    }
+    # TODO: remove these checks after the case_when kernel supports variable-width
+    # types (ARROW-13222)

Review comment:
       Can we just let the Arrow C++ library error out if it doesn't support the types? Is our error message that much better? Seems like extra work to try to keep this validation in sync with the C++ library.




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