Hi! I think I'm getting unexpected results from
case_when(), but since I'm a newbie, I thought I should check here before filing an issue.. I wasn't able to find a post about this on this site, stackoverflow or in the dplyr github repo issues.
eg. 1 shows the behaviour I expect. But in eg. 2, where the RHS of the second argument is length 2, the RHS of the first argument gets printed twice. This is true even when the LHS of the second argument is
FALSE (eg. 3).
When I try eg. 3 with an
first is only printed once (eg. 4), so it seems to be a
Thanks in advance!
library(dplyr) #> Warning: package 'dplyr' was built under R version 3.5.1 #> #> Attaching package: 'dplyr' #> The following objects are masked from 'package:stats': #> #> filter, lag #> The following objects are masked from 'package:base': #> #> intersect, setdiff, setequal, union first <- "A" second <- c("B", "C") third <- "D" ## eg. 1 case_when( TRUE ~ first, TRUE ~ third ) #>  "A" ## eg. 2 case_when( TRUE ~ first, TRUE ~ second ) #>  "A" "A" ## eg. 3 case_when( TRUE ~ first, FALSE ~ second ) #>  "A" "A" ## eg. 4 ifelse(TRUE, first, second) #>  "A" length(second) #>  2
Created on 2018-09-05 by the reprex