title: Why does the R case_when function work with the grepl function but not with grep function
body: <p>I am trying to manipulate a vector with the case_when function from dplyr. If I use the grepl function to test for certain text and change the output based on this, it works. If I use grep function it does not work.</p>
  
  <p>I would like to understand why this is.</p>
  
  <p>Code:</p>
  
  <pre><code>library(dplyr)
  
  x &lt;- 1:50
  v &lt;- case_when(
    x %% 35 == 0 ~ "fizz buzz",
    x %% 5 == 0 ~ "fizz",
    x %% 7 == 0 ~ "buzz",
    TRUE ~ as.character(x)
  )
  
  # This code works as expected    
  case_when(
    grepl("fizz", v) ~ "FFF",
    grepl("buzz", v) ~ "BZZ",
    TRUE ~ v
  )
  
  # This code gives an error: 
  # Error: `grep("buzz", v) == 1 ~ "BZZ"`, `TRUE ~ v` must 
  #        be length 10 or one, not 7, 50
  case_when(
    grep("fizz", v) == 1 ~ "FFF",
    grep("buzz", v) == 1 ~ "BZZ",
    TRUE ~ v
  )
  </code></pre>