Commits


Dragos Moldovan-Grünfeld authored and Jonathan Keane committed 268f9b9d852
ARROW-13799 [R] case_when error handling is capturing strings The approach I propose is simple - add an `abort()` if there is a `try-error` in the evaluated RHS of the `case_when()`. This error is then handled by `mutate()` which captures the call, forces a `collect()` and re-evaluates the `case_when()` call as a regular {dplyr} call. There are a couple of potential implications for this ☝🏻 approach: * we are working with the assumption that `case_when()` is only used inside `mutate()` and relying on `mutate()` to handle the error (via `abandon_ship()`). * the error is not captured at `case_when()` level (which would be a bit more informative), but rather at `mutate()` level (when it becomes a bit less specific, i.e. one-step removed). The error message at `case_when()` level is not surfaced. A follow-up question: do we want to implement a version of `case_when()` that works outside `mutate()`? ``` r record_batch(tbl) %>% mutate( cw = case_when(!(!(!(lgl))) ~ factor(chr), TRUE ~ fct) ) %>% collect() Warning: Expression case_when(!(!(!(lgl))) ~ factor(chr), TRUE ~ fct) not supported in Arrow; pulling data into R # A tibble: 10 × 8 int dbl dbl2 lgl false chr fct cw <int> <dbl> <dbl> <lgl> <lgl> <chr> <fct> <fct> 1 1 1.1 5 TRUE FALSE a a a 2 2 2.1 5 NA FALSE b b b 3 3 3.1 5 TRUE FALSE c c c 4 NA 4.1 5 FALSE FALSE d d d 5 5 5.1 5 TRUE FALSE e NA NA 6 6 6.1 5 NA FALSE NA NA NA 7 7 7.1 5 NA FALSE g g g 8 8 8.1 5 FALSE FALSE h h h 9 9 NA 5 FALSE FALSE i i i 10 10 10.1 5 NA FALSE j j j ``` <sup>Created on 2021-10-14 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)</sup> Closes #11417 from dragosmg/ARROW-13799_case_when_error_handling Lead-authored-by: Dragos Moldovan-Grünfeld <dragos.mold@gmail.com> Co-authored-by: Dragoș Moldovan-Grünfeld <dragos.mold@gmail.com> Signed-off-by: Jonathan Keane <jkeane@gmail.com>