title: Pass code to Input of Rmarkdown render function instead of a file
body: <p>I have a workflow with <code>Rmarkdown</code> and <code>render</code> that feels far from optimal.  Here is what I am currently doing.</p>
  
  <p>I have an <code>.R</code> script that may have several hundred lines of code already and several dozen objects in my environment.  Near or at the end of the script, I'd like to utilize <code>render</code> to generate some HTML output using objects in my current environment.  To accomplish this, I save the objects of interest and re-load them in the script that I pass to <code>render</code> all while being careful about working directories and where items are located relative to the script I will use to render the html document.</p>
  
  <p>Here is a reproducible example of my current workflow and an example of what I'd like to do.</p>
  
  <pre><code># Imagine I have a local data.frame/object I am interested in plotting to html via render
  iris_revised &lt;- iris
  
  # My current workflow is to save this object
  save(iris_revised, file = 'data/iris_revised.Rdata')
  
  # And then call another script via the render function
  rmarkdown::render('R/plot_iris_revised.R', output_format = 'html_document')
  </code></pre>
  
  <p>Where <code>R/plot_iris_revised.R</code> contains the following code.</p>
  
  <pre><code>library(ggplot2)
  load('../data/iris_revised.Rdata')
  
  for(Species in levels(iris_revised$Species)){
      cat('#', Species, '\n')
      p &lt;- ggplot(iris_revised[iris_revised$Species == Species,], aes(x = 
  Sepal.Length, y = Sepal.Width)) +
          geom_point()
      print(p)
  }
  </code></pre>
  
  <p>Ideally instead of the additional overhead of calling a different script, I'd be able to user <code>render</code> directly at the end of my current script, something akin to the code below (which obviously does not work).</p>
  
  <pre><code># Ideally I could just do something like this, where I could just render html in the same workflow
  input_text &lt;- "
  for(Species in levels(iris_revised$Species)){
      cat('#', Species, '\n')
      p &lt;- ggplot(iris_revised[iris_revised$Species == Species,], aes(x = 
  Sepal.Length, y = Sepal.Width)) +
          geom_point()
      print(p)
  }
  "
  rmarkdown::render(input_text, output_format = 'html_document')
  </code></pre>
  
  <p>I am looking for a solution <strong>without</strong> changing the original <code>.R</code> to <code>.Rmd</code> or an R notebook.</p>
  
  <p>Aside from the ideal capability I present above, I am open to general workflow suggestions of how to easily render some Rmarkdown output at the end of an <code>.R</code> script.</p>