How to convert R Markdown to HTML? I.e., What does "Knit HTML" do in Rstudio 0.96?

knitr, r, r-markdown, rstudio

Solution

Put `Sys.sleep(30)` in a chunk and you will see clearly what commands are called by RStudio. Basically they are

- `library(knitr); knit()` to get the markdown file;

- RStudio has internal functions to convert markdown to HTML;

The second step will be more transparent in the next version of the markdown package. Currently you can use `knitr::knit2html('your_file.Rmd')` to get a similar HTML file as RStudio gives you.

Update on 2019/09/17: The above answer applies to RStudio v0.96 (in the year 2012). Now R Markdown is compiled through `rmarkdown::render()`, which uses Pandoc instead of the retired R package markdown. See the post Relationship between R Markdown, Knitr, Pandoc, and Bookdown for more details.

Problem

What commands are run when pressing "Knit HTML" on an R Markdown file in Rstudio 0.96? My motivation is that I might want to run the same command when I'm in another text editing environment or I might want to combine the command in a larger `makefile`.

Original source

Related problems