title: add a series of steps to end of recipe in r
body: <p>The goal is to be able to add a series of new steps in sequence to the end of a recipe where the new steps are passed as arguments to a function. </p>
  
  <p>I can do what I want with a <code>for</code> loop:</p>
  
  <pre class="lang-r prettyprint-override"><code>library(tidyverse)
  suppressPackageStartupMessages(library(recipes))
  suppressPackageStartupMessages(library(rlang))
  
  add_steps_to_recipe &lt;- function(rec, new_steps) {
    rec_new &lt;- rec
    for (i in seq_along(new_steps)) {
      rec_new &lt;- eval_tidy(expr(rec_new %&gt;% !!new_steps[[i]]))
    }
    return(rec_new)
  }
  
  .pred_date &lt;- as.Date("2015-01-15")
  
  mtcars2 &lt;- mtcars %&gt;% mutate(hp_date = as.Date("2015-01-01"))
  mtcars2$hp_date[1:2] &lt;- as.Date("2015-02-01")
  
  rec1 &lt;- recipe(mtcars2, mpg ~ hp + hp_date)
  
  new_steps &lt;- exprs(
    step_mutate(hp = ifelse(hp_date &lt; .pred_date, hp, as.numeric(NA))),
    step_meanimpute(hp)
  )
  
  rec2 &lt;- add_steps_to_recipe(rec1, new_steps)
  
  juice(prep(rec2))
  </code></pre>
  
  <p>I can't seem to get it to work without using a <code>for</code> loop:</p>
  
  <pre class="lang-r prettyprint-override"><code>new_steps &lt;- expr(
    step_mutate(hp = ifelse(hp_date &lt; .pred_date, hp, as.numeric(NA))) %&gt;% step_meanimpute(hp)
  )
  
  add_steps_to_recipe &lt;- function(rec, new_steps) {
    eval_tidy(expr(rec %&gt;% !!new_steps))
  }
  
  rec2 &lt;- add_steps_to_recipe(rec1, new_steps)
  #&gt; Error in `%&gt;%`(., step_mutate(hp = ifelse(hp_date &lt; .pred_date, hp, as.numeric(NA))), : unused argument (step_meanimpute(hp))
  
  juice(prep(rec2))
  #&gt; Error in prep(rec2): object 'rec2' not found
  </code></pre>
  
  <p><sup>Created on 2020-02-24 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v0.3.0)</sup></p>
  
  <p>The problem is caused by the pipe in <code>new_steps</code>. If I just add one step, it works fine. I noticed also that the unquoted expression has an additional set of parentheses. Is there a way to remove an extra set of parentheses after unquoting?</p>