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

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


Reply via email to