Skip to content

Instantly share code, notes, and snippets.

@tmalsburg
Last active April 26, 2018 17:23
Show Gist options
  • Save tmalsburg/773608cb9cca7f4121ef34c50372a0cd to your computer and use it in GitHub Desktop.
Save tmalsburg/773608cb9cca7f4121ef34c50372a0cd to your computer and use it in GitHub Desktop.
Elisp function for rendering RMarkdown files to PDF. Shows the output of the render process in a separate window.
(defun tmalsburg-rmarkdown-render ()
"Compiles the current RMarkdown file to PDF and shows output of
the compiler process in a separate window."
(interactive)
(let* ((buf (get-buffer-create "*rmarkdown-render*"))
(temp-window (or (get-buffer-window buf)
(split-window-below -10)))
(command "Rscript -e 'library(rmarkdown); render(\"%s\", output_format=\"%s\")'")
(command (format command (buffer-file-name) "pdf_document")))
(set-window-buffer temp-window buf)
(with-selected-window temp-window
(goto-char (point-max)))
(start-process-shell-command "rmarkdown-process" buf command)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment