[ESS] Integration of pandoc using polymode+knitr

Ahmadou Dicko dicko.ahmadou at gmail.com
Mon Mar 10 19:32:15 CET 2014


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 6:28 PM, Ahmadou Dicko <dicko.ahmadou at gmail.com>wrote:

> 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>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> 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", 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, 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
>>> 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 mailing list
>>> 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
>> 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
> 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
twitter : @dickoah
github : github/dickoa <https://github.com/dickoa>
tel : +221 33 827 55 16
portable: +221 77 123 81 69


More information about the ESS-help mailing list