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

case_when not handling is.na statements #1999

Closed
tjmahr opened this issue Jul 6, 2016 · 4 comments
Closed

case_when not handling is.na statements #1999

tjmahr opened this issue Jul 6, 2016 · 4 comments

Comments

@tjmahr
Copy link
Contributor

tjmahr commented Jul 6, 2016

case_when doesn't seem to work on is.na statements unless they are the very first formula. I'm submitting a pull request.

library(dplyr)

x <- c(1:6, NA)

case_when(
  is.na(x) ~ "missing",
  TRUE ~ as.character(x)
)
#> [1] "1"       "2"       "3"       "4"       "5"       "6"       "missing"

case_when(
  is.na(x) ~ "missing",
  x %% 2 == 0 ~ "even",
  TRUE ~ as.character(x)
)
#> [1] "1"       "even"    "3"       "even"    "5"       "even"    "missing"

# NA is not recoded
case_when(
  x %% 2 == 0 ~ "even",
  is.na(x) ~ "missing",
  TRUE ~ as.character(x)
)
#> [1] "1"    "even" "3"    "even" "5"    "even" NA

Session info

devtools::session_info()
#> Session info --------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.3.1 (2016-06-21)
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  English_United States.1252  
#>  tz       America/Chicago             
#>  date     2016-07-06
#> Packages ------------------------------------------------------------------
#>  package    * version date       source        
#>  assertthat   0.1     2013-12-06 CRAN (R 3.0.2)
#>  DBI          0.4-1   2016-05-08 CRAN (R 3.2.5)
#>  devtools     1.12.0  2016-06-24 CRAN (R 3.3.1)
#>  digest       0.6.9   2016-01-08 CRAN (R 3.2.2)
#>  dplyr      * 0.5.0   2016-06-24 CRAN (R 3.3.1)
#>  evaluate     0.9     2016-04-29 CRAN (R 3.2.5)
#>  formatR      1.4     2016-05-09 CRAN (R 3.2.3)
#>  htmltools    0.3.5   2016-03-21 CRAN (R 3.2.4)
#>  knitr        1.13    2016-05-09 CRAN (R 3.2.3)
#>  magrittr     1.5     2014-11-22 CRAN (R 3.1.2)
#>  memoise      1.0.0   2016-01-29 CRAN (R 3.2.3)
#>  R6           2.1.2   2016-01-26 CRAN (R 3.2.3)
#>  Rcpp         0.12.5  2016-05-14 CRAN (R 3.2.5)
#>  rmarkdown    0.9.6   2016-05-01 CRAN (R 3.2.3)
#>  stringi      1.1.1   2016-05-27 CRAN (R 3.2.5)
#>  stringr      1.0.0   2015-04-30 CRAN (R 3.2.0)
#>  tibble       1.1     2016-07-04 CRAN (R 3.3.1)
#>  withr        1.0.2   2016-06-20 CRAN (R 3.3.1)
#>  yaml         2.1.13  2014-06-12 CRAN (R 3.1.0)
@hadley
Copy link
Member

hadley commented Jul 6, 2016

How did you learn about the <details> thing?

@tjmahr
Copy link
Contributor Author

tjmahr commented Jul 6, 2016

https://twitter.com/ericclemmons/status/749223563790471169

@krlmlr
Copy link
Member

krlmlr commented Dec 8, 2016

@hadley: PR has been merged, NEWS has been added.

@hadley
Copy link
Member

hadley commented Dec 8, 2016

Thanks!

@hadley hadley closed this as completed Dec 8, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants