1

As I understand it, the servr package enables edits to Rmd files to be viewed in HTML format in real time.

But does servr enable edits to Rnw files to be viewed in PDF format in real time?

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
luciano
  • 13,158
  • 36
  • 90
  • 130

1 Answers1

1

You may simply use an infinite loop with a Makefile to update PDF continuously when necessary. See https://github.com/yihui/servr/blob/master/R/make.R#L31-L35 for a simple function make_maybe(), and https://github.com/yihui/servr/blob/master/inst/examples/make1/Makefile for a simple Makefile (you need to change the target all and the make rule for %.pdf: %.Rnw). Then the loop looks like this in R (you can certainly also use shell scripts):

while (servr:::make_maybe()) {
  Sys.sleep(1)
}

If you are not familiar with make, it is also easy to implement it in pure R. You just need to check the mtime of file.info('your_file.Rnw'), and whenever it is updated, recompile the Rnw file. Well, since it is easy, I just wrote a function and added it to the development version of knitr. With knitr (>= 1.11.20), you can just call the function knit_watch('your_file.Rnw', knit2pdf) to update the PDF continuously. Note you need a PDF viewer that can update itself as the PDF file gets updated (to my old knowledge, Acrobat reader on Windows does not work; if you do not use Windows, you are probably good to go by default).

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419