[ESS] Integration of pandoc using polymode+knitr
Mathieu Basille
basille.web at ase-research.org
Mon Mar 10 19:28:21 CET 2014
Dear Ahmadou,
As far as I can tell, the approach is not a lot different than the 'pandoc'
function from knitr. For instance, you can specify to knitr the pandoc
options, or a file where to look for these options, or as a chunk embedded
in the main file. Basically, pandoc from knitr is a mere wrapper to a
system call to 'pandoc'. See: http://yihui.name/knitr/demo/pandoc/
In the end, my issue is not really what function to use (pandoc from knitr,
render from rmarkdown, ...), but how to use it from Emacs + polymode + ESS.
Which I couldn't do so far.
However, thinking a little bit more about it, maybe my approach of the
whole problem is wrong, and instead of using a R function, I should try to
have a direct Lisp call to pandoc from within Emacs? Once again, I'm stuck
with my very limited Lisp skills... Any help on this appreciated!
Sincerely,
Mathieu.
Le 03/10/2014 01:15 PM, Ahmadou Dicko a écrit :
> 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
--
~$ 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