title: Save knitr::kable() output to html file R
body: <p>I have a knitr_kable output that I want to save as an HTML document from R. I need this to run automatically from my R script with no human involvement. For example:</p>
  
  <pre><code>dt &lt;- mtcars[1:5, 1:6]
  kable(dt, "html") %&gt;% kable_styling(bootstrap_options = c("striped", "hover"))
  </code></pre>
  
  <p>This has html output but the class is <code>knitr_kable</code> so I can't write it to a table or html file because it cannot be coerced to a dataframe.</p>
  
  <pre><code>class(kable(dt, "html"))
  [1] "knitr_kable"
  </code></pre>
  
  <p>Does anyone have a method for saving one of these kables as an html file?</p>
  
  <hr>
  
  <p>I've tried:</p>
  
  <pre><code>library(xml2)
  options(knitr.table.format = "html") 
  write_html(kable(dt, "html"), "df.html")))
  </code></pre>
  
  <p>This has error:</p>
  
  <blockquote>
    <p>Error in UseMethod("write_html") :    no applicable method for
    'write_html' applied to an object of class "knitr_kable"</p>
  </blockquote>
  
  <hr>
  
  <p>My guess would be that the knitr_kable object must first be coerced to an html object and then saved as html file. But I'm not sure how to do that.</p>