title: How can I add a baseplot with no fixed values to a document
body: <p>I want to add a baseplot to a word document.</p>
  <p>In the documentation for the officer package there's an example that uses the plot_instr function:</p>
  <pre><code>anyplot &lt;- plot_instr(code = {
    barplot(1:5, col = 2:6)
    })
  
  doc &lt;- read_docx()
  doc &lt;- body_add(doc, anyplot, width = 5, height = 4)
  print(doc, target = tempfile(fileext = &quot;.docx&quot;))
  </code></pre>
  <p>I want to add a plot to a word document inside a function so I need variable input for the plot function like this:</p>
  <pre><code>x=1:5
  cols=2:6
  anyplot &lt;- plot_instr(code = {
      barplot(x,col=cols)
  })
  
  doc &lt;- read_docx()
  doc &lt;- body_add(doc, anyplot, width = 5, height = 4)
  print(doc, target = tempfile(fileext = &quot;.docx&quot;))
  </code></pre>
  <p>But the code above doesn't work and I can't find any other examples of plot_instr usage.</p>