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 support of NA values #2000

Merged
merged 2 commits into from Aug 24, 2016
Merged

case_when support of NA values #2000

merged 2 commits into from Aug 24, 2016

Conversation

@tjmahr
Copy link
Contributor

@tjmahr tjmahr commented Jul 6, 2016

#1999. case_when stores results of formula evaluations as vectors in query. These values are used to determine which elements in the input vector need to be overwritten. But an NA in an earlier query result would infect TRUE values in other queries. Therefore, I've updated the function to treat NAs as FALSE (when it comes to determining which values need to be replaced).

Also, added a unit test.

@@ -53,6 +53,7 @@ case_when <- function(...) {
env <- environment(f)

query[[i]] <- eval(f[[2]], envir = env)
query[[i]][is.na(query[[i]])] <- FALSE
if (!is.logical(query[[i]])) {
stop("LHS of case ", i, " (", deparse_trunc(f_lhs(f)),
") is ", typeof(query[[i]]), ", not logical",
Copy link
Member

@hadley hadley Jul 6, 2016

I think it would make more sense to handle in the | below: replaced | (query[[i]] & !is.na(query[[i]]))

Copy link
Contributor Author

@tjmahr tjmahr Jul 6, 2016

Thanks. Done

@hadley hadley merged commit 9425d6e into tidyverse:master Aug 24, 2016
3 checks passed
@hadley
Copy link
Member

@hadley hadley commented Aug 24, 2016

Can you please give me a bullet point to put in NEWS?

@tjmahr
Copy link
Contributor Author

@tjmahr tjmahr commented Aug 24, 2016

  • Improved handling of NA values in case_when (#1999). Previously, NA-recoding formulas like is.na(x) ~ "missing" only worked if they were the first formula given to case_when.
* Improved handling of NA values in `case_when` (#1999). Previously, NA-recoding formulas like `is.na(x) ~ "missing"` only worked if they were the first formula given to `case_when`.

@lock
Copy link

@lock lock bot commented Jan 18, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants