dragosmg opened a new pull request #11417:
URL: https://github.com/apache/arrow/pull/11417


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


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