Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translation from case_when to fcase() will throw error when T is used instead of TRUE. #272

Closed
gitgud5000 opened this issue Jul 19, 2021 · 2 comments · Fixed by #274
Closed

Comments

@gitgud5000
Copy link

When calling T instead of TRUE inside this a case_when using dplyr causes the function to fail.

This works:

iris %>% 
lazy_dt() %>%
  mutate(new_col = case_when( Sepal.Length> 4.5 ~ "foo",
                              TRUE ~ "bar"))

This breaks:

iris %>% 
lazy_dt() %>%
  mutate(new_col = case_when( Sepal.Length> 4.5 ~ "foo",
                              T ~ "bar"))

Error message output to the console:

Error in fcase(Sepal.Length > 4.5, "foo", TRUE, "bar") : 
  Argument #3 has a different length than argument #1. Please make sure all logical conditions have the same length.
@gitgud5000 gitgud5000 changed the title case_when fails if T is used insteaRUEd of TRUE case_when fails if T is used instead of TRUE Jul 19, 2021
@gitgud5000 gitgud5000 changed the title case_when fails if T is used instead of TRUE case_when fails whenT is used instead of TRUE Jul 19, 2021
@gitgud5000 gitgud5000 changed the title case_when fails whenT is used instead of TRUE case_when fails when T is used instead of TRUE Jul 19, 2021
@gitgud5000 gitgud5000 changed the title case_when fails when T is used instead of TRUE Translation from case_when to fcase() will throw error when T is used instead of TRUE. Jul 19, 2021
@markfairbanks
Copy link
Collaborator

Thanks for catching this. I added a fix in #269 that will address this issue once it's merged.

@markfairbanks
Copy link
Collaborator

@NZambranoc All set

library(dplyr, warn.conflicts = FALSE)
library(dtplyr)

iris %>% 
  lazy_dt() %>%
  mutate(new_col = case_when(Sepal.Length > 4.5 ~ "foo",
                             T ~ "bar"))
#> Source: local data table [150 x 6]
#> Call:   copy(`_DT1`)[, `:=`(new_col = fcase(Sepal.Length > 4.5, "foo", 
#>     rep(TRUE, .N), "bar"))]
#> 
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species new_col
#>          <dbl>       <dbl>        <dbl>       <dbl> <fct>   <chr>  
#> 1          5.1         3.5          1.4         0.2 setosa  foo    
#> 2          4.9         3            1.4         0.2 setosa  foo    
#> 3          4.7         3.2          1.3         0.2 setosa  foo    
#> 4          4.6         3.1          1.5         0.2 setosa  foo    
#> 5          5           3.6          1.4         0.2 setosa  foo    
#> 6          5.4         3.9          1.7         0.4 setosa  foo    
#> # … with 144 more rows
#> 
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants