Personally, it looks like a bug, but documentation does cover your case specifically (I've added not there and highlighted the bits that are important):
The LHS must evaluate to a logical vector. The RHS does not need to be logical, but all RHSs must evaluate to the same type of vector.
Both LHS and RHS may have the same length of either 1 or n. The value of n must be consistent across all cases. The case of n == 0 is treated as a variant of n != 1.
This means that from the point of view of case_when it does the right thing in your second and third examples. Specifically, it would complain if you do something like this:
library(dplyr)
first <- "A"
second <- c("B", "C")
third <- c("D", "E", "F")
case_when(
TRUE ~ first,
TRUE ~ second,
TRUE ~ third
)
#> Error: `TRUE ~ third` must be length 2 or one, not 3
Created on 2018-09-05 by the reprex package (v0.2.0).
But if you do this:
library(dplyr)
first <- "A"
second <- c("B", "C", "3")
third <- c("D", "E", "F")
case_when(
TRUE ~ first,
TRUE ~ second,
TRUE ~ third
)
#> [1] "A" "A" "A"
everything is as in your example. Specifically, case_when will recycle the result and make sure that all possible results have the same length, even if it only looks at first case.