title: How to generate html report directly from R script?
body: <p>I have a R script, say myscript.R, which does a lot of stuff and the final output is a list object with many different components.
  I'd like to pass the list to a function which generate a html report "injecting" the various components in a preformatted template.
  the code is something like this:</p>
  
  <pre><code>main_fun = function() {
  
    # do some stuff 
  
    d1 = list(
      a = 42,
      b = "foo",
      c = c("elem1","elem2","elem3")
    )
  
    generate_report(d1)
  }
  
  generate_report = function(data) {
    # generate html report
  }
  </code></pre>
  
  <p>(actually obviously the value of the components of the list is the output of the "do some stuff" part)</p>
  
  <p>I'm new to R Markdown and knitr, there is a way to dynamically generate the html report calling a function within the code? without a .rmd markdown file and without passing the entire script to a function like</p>
  
  <pre><code>rmarkdown::render('myscript.R')
  </code></pre>