Rmarkdown knitr doesn't process code chunks when generating preview or html doc (and only shows code literals)

Oh that is why. This is because knitr is seing a HTML file as source, and it won't process the code chunk syntax used as markdown. For knitting a HTML file, there is another syntax. But .Rmd is the recommended way.

So conclusion: the file to render needs to be a .Rmd file.

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it: