title: dplyr::recode in conjunction with stringr::str_detect()
body: <p>I am trying to recode a character variable with <code>dplyr::recode()</code> and <code>stringr::str_detect()</code>. I realize that this can be done with <code>dplyr::case_when()</code>, as documented here: <a href="https://community.rstudio.com/t/recoding-using-str-detect/5141" rel="nofollow noreferrer">https://community.rstudio.com/t/recoding-using-str-detect/5141</a>, but I am convinced that there has to be a way of doing it via <code>recode()</code>.</p>
  
  <p>Consider this case:</p>
  
  <pre><code>library(tidyverse)
  rm(list = ls())
  
  data &lt;- tribble(
    ~id, ~time,
    #--|--|
    1, "a",
    2, "b",
    3, "x"
  )
  </code></pre>
  
  <p>I would like to replace the "x" in the dataframe with a "c" via <code>str_detect()</code> and here's how I'd do it:</p>
  
  <pre><code>data %&gt;% 
   mutate(time = recode(data$time, str_detect(data$time, "x") = "c"))
  </code></pre>
  
  <p>But that doesn't work:</p>
  
  <blockquote>
    <p>Error: unexpected '=' in:
    "data %>% 
      mutate(time = recode(data$time, str_detect(data$time, "x") ="</p>
  </blockquote>
  
  <p>Apparently R doesn't know what to do with the last <code>=</code>, but I believe it has to be there for the recode function, as demonstrated here:</p>
  
  <pre><code>recode(data$time, "x" = "c")
  </code></pre>
  
  <p>This executes properly, as does this:</p>
  
  <pre><code>str_detect(data$time, "x")
  </code></pre>
  
  <p>But this does not:</p>
  
  <pre><code>recode(data$time, str_detect(data$time, "x") = "c")
  </code></pre>
  
  <p>Is there a way of getting these two functions to work with each other?</p>