[ESS] Integration of pandoc using polymode+knitr

Mathieu Basille basille.web at ase-research.org
Mon Mar 10 21:10:45 CET 2014


Dear Ahmadou,

That is actually more or less what I've been trying to do! (modulo the use 
of knitr::pandoc instead of rmarkdown::render)
But I've been unable to succeed so far, and the problem lies more on the 
Lisp side (my knowledge and understanding of Lisp are really limited)

However, I still wonder whether I should not be trying to call directly the 
pandoc library installed on my system, and not through a R wrapper... (but 
it does not help me, for the reason stated above!) I just found the 
pandoc-mode for Emacs [1], but this is a dead-end for me since I don't know 
how to make convert the .md file (that is not necessarily loaded in a 
buffer) and not the actual content of the .Rmd file loaded in the current 
buffer.

There's another lead here [2], but again I'm stuck in the Lisp 
modifications required for my use (same problem here: how to tell to use 
the .md file instead of the .Rmd...).

Thanks,
Mathieu.


[1] http://joostkremers.github.io/pandoc-mode/


Le 03/10/2014 02:28 PM, Ahmadou Dicko a écrit :
> Using the rmarkdown package, you can use ess-swv-run-in-R elisp function to
> create ess-swv-pandoc (ess-swv-pandoc.el) and modify the R function
> .ess_weaver to add rmarkdown::render option (ess_weave.R).
> Make sure that that ess-swv-pandoc.el in your path and your R process use
> the new .ess_weaver function.
>
> Hope it helps
>
>
>
> On Mon, Mar 10, 2014 at 5:15 PM, Ahmadou Dicko <dicko.ahmadou at gmail.com
> <mailto:dicko.ahmadou at gmail.com>> wrote:
>
>     Why not simply build ess-swv-pandoc on top of  the new rmarkdown
>     <http://rmarkdown.rstudio.com/> package
>     <https://github.com/rstudio/rmarkdown>.
>
>     You example will  be :
>
>     library(rmarkdown)
>     render("test.Rmd <http://test.md>", html_document())
>
>     There are a lot of advantages with this approach, for example you can
>     specify all pandoc options using a Yaml header in the .Rmd file.
>
>
>
>
>     On Mon, Mar 10, 2014 at 3:53 PM, Mathieu Basille
>     <basille.web at ase-research.org <mailto:basille.web at ase-research.org>> wrote:
>
>         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
>         polymode-mode-map:
>
>         (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:
>
>         library(knitr)
>         knit("test.Rmd")
>         pandoc("test.md <http://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)))
>              (save-excursion
>                (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))
>                       (pandoc-cmd
>                        (format "require(knitr); pandoc(%s.md <http://s.md>,
>         output = \"html\")" md-file)))
>                  (message "Running pandoc on %s.md <http://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
>         http://ase-research.org/__basille <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
>
>         ________________________________________________
>         ESS-help at r-project.org <mailto:ESS-help at r-project.org> mailing list
>         https://stat.ethz.ch/mailman/__listinfo/ess-help
>         <https://stat.ethz.ch/mailman/listinfo/ess-help>
>
>
>
>
>     --
>     Ahmadou H. DICKO
>     statistician economist (Ingénieur Statisticien Économiste)
>     PhD candidate in Climate change economics
>     Faculty of economics and managment - Cheikh Anta Diop University
>     West African Science Service Center on Climate Change and Adaptated
>     Land Use (WASCAL)
>     Center for Development Research (ZEF) - University of Bonn
>     email : ahmadou.dicko at ucad.edu.sn <mailto:ahmadou.dicko at ucad.edu.sn>
>     twitter : @dickoah
>     github : github/dickoa <https://github.com/dickoa>
>     tel : +221 33 827 55 16
>     portable: +221 77 123 81 69
>
>
>
>
> --
> Ahmadou H. DICKO
> statistician economist (Ingénieur Statisticien Économiste)
> PhD candidate in Climate change economics
> Faculty of economics and managment - Cheikh Anta Diop University
> West African Science Service Center on Climate Change and Adaptated Land
> Use (WASCAL)
> Center for Development Research (ZEF) - University of Bonn
> email : ahmadou.dicko at ucad.edu.sn <mailto:ahmadou.dicko at ucad.edu.sn>
> twitter : @dickoah
> github : github/dickoa <https://github.com/dickoa>
> tel : +221 33 827 55 16
> portable: +221 77 123 81 69

-- 

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