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 Error: when having only one condition and the vector length is greater than 1 #2909

Closed
AndreMikulec opened this issue Jun 25, 2017 · 1 comment
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@AndreMikulec
Copy link

AndreMikulec commented Jun 25, 2017

case_when errors when having only one condition and the vector length is greater than 1

library(dplyr)

x <- 1
dplyr::case_when(
         TRUE ~   x
)
[1] 1

x <- 1:2
dplyr::case_when(
         TRUE ~   x
)
Error: RHS of case 1 (x) must be length 1 (the first output), not 2

But the error seems deceptive. Maybe the left hand side needs a vector the same length as 'x'.
If so, TRUE ( a single ) value, can not be allowed ( or allowed to be a default. ) Alternately, a single value (TRUE) can only be allowed as the default and the case must have at least 2 conditions. If so, this 'feature' should be in the 'help documentation.'

x <- 1:2
dplyr::case_when(
       x == x ~ x
)
[1] 1 2

x <- 1:2
dplyr::case_when(
       TRUE ~ x
)
Error: RHS of case 1 (x) must be length 1 (the first output), not 2
@krlmlr
Copy link
Member

krlmlr commented Jul 12, 2017

Thanks, confirmed.

@krlmlr krlmlr added bug an unexpected problem or unintended behavior data frame labels Jul 12, 2017
@krlmlr krlmlr modified the milestone: 0.7.3 Aug 16, 2017
krlmlr added a commit to krlmlr/dplyr that referenced this issue Aug 23, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jun 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants