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



##########
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)
+    has_bad_r_type <- inherits(value[[i]], c("character", "raw", "list", 
"factor"))
+    has_bad_arrow_type <- inherits(value[[i]], "Expression") &&
+      value[[i]]$type_id() %in% Type[c(
+      "STRING", "BINARY", "LIST", "MAP", "STRUCT", "SPARSE_UNION",
+      "DENSE_UNION", "DICTIONARY", "EXTENSION", "FIXED_SIZE_LIST",
+      "LARGE_STRING", "LARGE_BINARY", "LARGE_LIST")]

Review comment:
       Some of these types are not testable in R but are obviously 
variable-width. For the ones that are testable in R, I tested them to confirm 
they don't yet work with the `case_when` kernel, and I tested all the others to 
confirm they do work.




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