[ESS] Integration of pandoc using polymode+knitr

Mathieu Basille basille.web at ase-research.org
Wed Mar 12 03:19:37 CET 2014


Dear Yihui,

Le 03/11/2014 10:04 PM, Yihui Xie a écrit :
> I'm glad that your problem was solved. Just as Ahmadou mentioned, we
> are heading towards rmarkdown (http://rmarkdown.rstudio.com), which is
> a nice alternative to knitr::pandoc().

The nice thing with the (not so nice) function I ended up with is that it 
would be fairly easy to use any other function, such as rmarkdown::render 
instead of knitr::pandoc. As for me, as I already use knitr (obviously) to 
knit, and pandoc is also installed on my system, it makes more sense to use 
what's available! Or maybe I'm missing the obvious: is there a strong 
argument in favor of rmarkdown::render instead of knitr::pandoc?

Mathieu.


> Regards,
> Yihui
> --
> Yihui Xie <xieyihui at gmail.com>
> Web: http://yihui.name
>
>
> On Mon, Mar 10, 2014 at 8:59 PM, Mathieu Basille
> <basille.web at ase-research.org> wrote:
>> Le 03/10/2014 09:16 PM, Ed Kademan a écrit :
>>>
>>>
>>> [...]
>>>
>>> When you define a function you need to include an argument list. Your code
>>> should probably start out looking something like this
>>>
>>> (defun ess-swv-pandoc ()
>>>      (interactive)
>>>
>>>     "Run Pandoc on the associated .md file."
>>>
>>
>> Ah, that's perfect! Just what I was missing. Well, this shows how bad I am
>> regarding Lisp! Thanks Ed!
>>
>> Here is my working function, definitely not a clean approach, and totally
>> dependent on my system, but it should get those people interested started,
>> and it's working at least for me:
>>
>> (defun ess-swv-pandoc ()
>>
>>    "Run Pandoc on the associated .md file."
>>    (interactive)
>>
>>    (let* ((rmd-buf (current-buffer)))
>>      (save-excursion
>>        (let* ((sprocess (ess-get-process ess-current-process-name))
>>               (sbuffer (process-buffer sprocess))
>>               (md-filename (file-name-sans-extension (buffer-file-name)))
>>               (buf-coding (symbol-name buffer-file-coding-system))
>>               (pandoc-cmd
>>                (format "require(knitr); pandoc(\"%s.md\", format =
>>                \"html\", config =
>>                \"/home/mathieu/.emacs.d/config/config.pandoc\")"
>>                md-filename)))
>>          (message "Running pandoc on %s.md" md-filename)
>>
>>          (ess-execute pandoc-cmd 'buffer nil nil)
>>          (switch-to-buffer rmd-buf)
>>          (ess-show-buffer (buffer-name sbuffer) nil)))))
>> (define-key polymode-mode-map [(control f5)] 'ess-swv-pandoc)
>>
>> Since I associated (f5) to 'ess-swv-weave, I can first weave the .Rmd file
>> using knitr (f5) and then render as HTML the resulting file using the
>> knitr::pandoc (C-f5). All Pandoc options are then tuned in
>> /home/mathieu/.emacs.d/config/config.pandoc, see [1] for more details.
>>
>> Now, this does exactly what I wanted, thanks a lot!
>> Mathieu.
>>
>>
>> [1] http://yihui.name/knitr/demo/pandoc/
>>
>>
>>
>> --
>>
>> ~$ whoami
>> Mathieu Basille, PhD
>>
>> ~$ locate --details
>> University of Florida \\
>> Fort Lauderdale Research and Education Center
>> (+1) 954-577-6314
>> http://ase-research.org/basille

-- 

~$ whoami
Mathieu Basille, PhD

~$ locate --details
University of Florida \\
Fort Lauderdale Research and Education Center
(+1) 954-577-6314
http://ase-research.org/basille

~$ 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