title: R Create and execute an officer string
body: <p>I want to create a powerpoint stack with pdfs I have created. I'm attempting to do this with officer. It works fine manually but I want to write the pdf out in code. Using a <code>Two Content</code> layout I want to write the name of the pdf into the title and paste the pdf itself into the body.  Here is the code I've developed so far.</p>
  
  <pre><code>library(officer)
  library(magrittr)
  pdfList &lt;- c("pdf1.pdf", "pdf2.pdf", "pdf3.pdf")
  pdfDir &lt;- "pdfDir"
  my_pres&lt;-read_pptx("presentations/blank.pptx") # a blank pptx from powerpoint
  pageStart &lt;- "add_slide(layout='Two Content', master='Office Theme') %&gt;% " 
  titleListPre &lt;-  "ph_with_text(type = 'title', str = '"
  titleListPost &lt;- "') %&gt;% "
  imageListPre &lt;- "ph_with_img(src = 'graphics/SSPs/final/"
  imageListPost &lt;- "', type = 'body') "
  
  for (i in pdfList) {
    titleString &lt;- paste0(titleListPre, i, titleListPost)
    imageString &lt;- paste0(imageListPre, i, imageListPost)
    finalString &lt;- paste0(pageStart, titleString, imageString)
     my_pres &lt;- my_pres %&gt;%  eval(parse(text = finalString))
  }
  </code></pre>
  
  <p>The problem I'm having is the last line in the <code>for</code> loop. If I manually construct that line, as in the following, it works</p>
  
  <pre><code>my_pres &lt;- my_pres %&gt;% add_slide(layout='Two Content', master='Office Theme') %&gt;% ph_with_text(type = 'title', str = 'pdf1.pdf') %&gt;% ph_with_img(src = 'graphics/SSPs/final/pdf1.pdf', type = 'body')
  </code></pre>
  
  <p>But the eval/parse approach doesn't work (with this message "<code>invalid 'envir' argument of type 'expression</code>") and neither does as.formula(finalString)</p>