title: Dynamic `case_when` that allows for different number of conditions and conditions itself
body: <p>I'm looking for a dynamic way to specify some &quot;condition parameters&quot; and then feed that to a <code>case_when</code> operation or something else if better suited for that problem.</p>
  <p>My goal is to separate the specification of the conditions from the case_when call, e.g. so that a user can just type in the condition in a text file or a list in R and then I would take that info and feed it to case_when (or any other function if more appropriate).</p>
  <p>Assuming the following data where I want to create an additional variable that recodes <code>x</code>, I could do:</p>
  <pre><code>df &lt;- data.frame(x = 1:10)
  
  df |&gt;
    mutate(x2 = case_when(x &lt; 4 ~ 1,
                          x &gt;= 4 &amp; x &lt;=7 ~ 2,
                          TRUE ~ 3))
  </code></pre>
  <p>Now, what I want to achieve is to make this code flexible in a way that I can externally specify the case_when conditions and then do the recoding.</p>
  <p>E.g. it might look like:</p>
  <pre><code>all_conditions &lt;- list(1 = &quot;x &lt; 2&quot;,
                         2 = &quot;x &gt;= 2 &amp; x &lt; 5&quot;,
                         3 = &quot;x &gt;= 5 &amp; x &lt; 9&quot;,
                         4 = &quot;TRUE&quot;)
  </code></pre>
  <p>And then I could do some sort of:</p>
  <pre><code>df |&gt;
    mutate(x2 = do(case_when, all_conditions))
  </code></pre>
  <p>While the example shows a numeric type of variable for which the solution of @Mael works, the solution should also work for character vars where the condition might look like <code>x == &quot;abc&quot; | x == &quot;def&quot;</code>.</p>