Search code examples
rstudior-markdownpandocmiktex

Is it possible in RStudio to speed up the PDF preview in Sumatra after compiling?


I had to reinstall everything on my computer. After reinstallation of R, Rstudio, Pandoc and MikTex, the preview of knitted PDFs using RStudio and Sumatra takes a VERY long time. Prior to the reinstallation, the whole process tok only a few seconds. Now I have to wait more than thirty seconds for the Sumatra preview to be completed. The process somehow halts for a while between the

output file: MyFile.knit.md

and

Output created: volatility2.pdf

part of the output being printed in the R Markdown console.

I'm using the Knit to PDF option in RStudio, and I'm on a windows 7 64 bit system. I'm hoping some of you have a few suggestions, because this little hickup really messes up my workflow. The same problem occurs for all .Rmd files I've tested.


Solution

  • If you knit while working on the document to preview the final output, there might be a workaround:

    RStudio will soon release a new document type called html_notebook, which is already available in the preview release. Unlike standard .rmd files, notebooks are not knitbut previewed:

    Ordinary R Markdown documents are “knit”, but notebooks are “previewed”. While the notebook preview looks similar to a rendered R Markdown document, the notebook preview does not execute any of your R code chunks; it simply shows you a rendered copy of the markdown in your document along with the most recent chunk output. This preview is generated automatically whenever you save the notebook ... [source].

    This means that you are able to see the output instantly, as the notebook updates changes to your .rmd file, rather thank knitting the entire document.

    As Jonathan McPherson points out in the comments section of this manual, the notebooks were designed so that you can simply replace html_notebook with e.g., pdf_document for seamless transition between file formats.

    In other words, you could use the notebook format while working on the file, and only knit the document once after changing html_notebook to pdf_document for your final version (for automated conversion see e.g., this answer).