knit HTML does not save html in vignettes/

2019-03-26 15:10发布

问题:

So I have a vignette, vignettes/test-vignette3.Rmd:

---
title: "Sample Document"
output:
  html_document:
    highlight: kate
    theme: spacelab
    toc: yes
  pdf_document:
    toc: yes
---

Header
=========

When I hit the knit HTML button, I get the following:

processing file: test-vignette3.Rmd
output file: test-vignette3.knit.md


Output created: /tmp/RtmpKVpegL/preview-5ef42271c0d5.dir/test-vignette3.html

However, if I copy this file to inst/doc and hit the knit HTML button, I get:

processing file: test-vignette3.Rmd
output file: test-vignette3.knit.md


Output created: test-vignette3.html

My questions are:

  1. How do I get RStudio to save the output from knit HTML on vignettes/test-vignette3.Rmw to the vignettes directory?
  2. How do I get RStudio to not delete test-vignette3.knit.md during the knit HTML procedure? (I'd like to have the .md so people can read it on my github repo.)

I'm running RStudio version 0.98.836, rmarkdown version 0.1.98 and knitr version 1.5.

回答1:

Actually you should not keep the .html output under vignettes/, because the vignette output is supposed to be generated by R CMD build. R may fail to recompile your vignettes if the HTML output files have already been there when you build the source package, which means you are likely to see old (and possibly wrong) results because the HTML file was not generated from the latest version of the .Rmd file. Therefore RStudio intentionally avoid writing the HTML files in the vignetttes directory.

If you choose to ignore the warning above, you can certainly run rmarkdown::render('your-vignette.Rmd') in the R console.

For the second question, I do not recommend you to do that, either, because Github renders the markdown to HTML differently (compared to the Pandoc conversion done through the rmarkdown package). Normally the package vignettes are shown on CRAN, see, for example, the knitr page on CRAN. However, because the rmarkdown package is not on CRAN yet, you cannot use the vignette engine knitr::rmarkdown at the moment (I guess we are not too far away from the CRAN release now). You can consider pushing the HTML files to Github pages, though.