title: How to generate multiple files from r script function with knitr
body: <p>I would like to generate a number of reports from an r script. I would like to avoid the duplication needed when compiling from rmd files and I'd like to generate the reports from the r script itself if possible.</p>
  
  <p>The script has a function which should generate each report from a list of dataframes where each report represents the processing of one dataframe. I just can't understand how to generate each report separately. At the moment the report shows all of the dataframes in one file</p>
  
  <p>The original script is long so I have provided a minimal version below. </p>
  
  <pre><code>    structure(list(a = structure(c(1L, 3L, 2L), .Label = c("boo", 
      "saa", "yaew"), class = "factor"), b = structure(c(2L, 3L, 
      1L), .Label = c("mfds", "shu", "ren"), class = "factor"), c = structure(c(2L, 
      1L, 3L), .Label = c("22", "23", "5345"), class = "factor")), .Names = c("a", 
      "b", "c"), row.names = c(NA, -3L), class = "data.frame")
  
      ReportOp&lt;-function(n) { 
    this_is_a_name &lt;- n; 
    this_is_my_data &lt;- ldf[[n]] 
  
    #' ---
    #' author: Me
    #' date:
    #' ---
  
    #+results='asis', echo=FALSE
    knitr::kable(this_is_my_data, digits = 2)
    #'
  } 
  </code></pre>
  
  <p>At the moment I am just generating the report with everything in it using the<code>compile notebook</code> button in R studio.</p>
  
  <p>I tried using <code>knitr::spin</code> on the above script as follows from a separate file:</p>
  
  <pre><code>library(knitr)
  o=spin('/Users/sebastianzeki/Desktop/UntitledTBB.R')
  knit2html(o,output="/Users/sebastianzeki/Desktop/out.html")
  </code></pre>
  
  <p>but again I only get one report outputted rather than three.</p>