[ESS] Integration of pandoc using polymode+knitr

Mathieu Basille basille.web at ase-research.org
Mon Mar 10 16:53:58 CET 2014

Dear list,

As a happy user of Emacs+ESS for years, I happily welcomed the new 
polymode, most notably to edit .Rmd (R Markdown) documents. It's very easy 
to weave the file, e.g. using M-n s (ess-swv-weave), with knitr defined as 
the ess-swv-processor.

Personally, I also added M-n s as the shortcut for ess-swv-weave in 

(define-key polymode-mode-map "\M-ns" 'ess-swv-weave)

Maybe not the cleanest approach, but it allows to weave from anywhere in 
the document.

Now, I'd like to integrate the use of pandoc after the .Rmd has been 
weaved. A typical workflow in R would be:

pandoc("test.md", format = "html")

While the first step (knit) is perfectly handled by ess-swv-weave, I don't 
know any solution for the second part. I thus tried to mimic different 
functions from ESS, to no avail because of my virtually NULL skills of Lisp 
programming. The closest I could come was:

(defun ess-swv-pandoc
   "Run Pandoc on the associated .md file."
   (let* ((rmd-buf (current-buffer)))
       (let* ((sprocess (ess-get-process ess-current-process-name))
              (sbuffer (process-buffer sprocess))
              (md-file (buffer-file-name))
              (buf-coding (symbol-name buffer-file-coding-system))
	      (format "require(knitr); pandoc(%s.md, output = \"html\")" md-file)))
	(message "Running pandoc on %s.md" md-file)
         (ess-execute pandoc-cmd 'buffer nil nil)
         (switch-to-buffer rmd-buf)
         (ess-show-buffer (buffer-name sbuffer) nil)))))

This attempt miserably fails with: "Wrong type argument: commandp, 
ess-swv-pandoc", and this is where I am stuck.

I'd appreciate if a good soul could shed some light on this!

All the best,
Mathieu Basille.


~$ whoami
Mathieu Basille, PhD

~$ locate --details
University of Florida \\
Fort Lauderdale Research and Education Center
(+1) 954-577-6314

~$ fortune
« Le tout est de tout dire, et je manque de mots
Et je manque de temps, et je manque d'audace. »
  -- Paul Éluard

More information about the ESS-help mailing list