rmarkdown
rmarkdown copied to clipboard
Pandoc args conditional to version should be set in pre_processor
What we describe in https://bookdown.org/yihui/rmarkdown-cookbook/install-pandoc.html to run rmarkdown::find_pandoc()
in setup chunk does not work in some case.
My pandoc version is
rmarkdown::pandoc_version()
# [1] ‘3.1.7’
But now I am trying to use an old one.
---
title: test
output:
html_document:
self_contained: true
---
```{r}
rmarkdown::find_pandoc(cache = FALSE, dir = dirname(pandoc::pandoc_bin("2.7.3")))
```
This will throw an error
==> rmarkdown::render('C:/Users/chris/Documents/DEV_R/rmarkdown/test.Rmd', encoding = 'UTF-8');
++ Activating rlang global_entrace
processing file: test.Rmd
"C:/Users/chris/AppData/Local/r-pandoc/r-pandoc/2.7.3/pandoc" +RTS -K512m -RTS test.knit.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output test.html --lua-filter "C:\Users\chris\AppData\Local\R\win-library\4.3\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\chris\AppData\Local\R\win-library\4.3\rmarkdown\rmarkdown\lua\latex-div.lua" --embed-resources --standalone --variable bs3=TRUE --section-divs --template "C:\Users\chris\AppData\Local\R\win-library\4.3\rmarkdown\rmd\h\default.html" --no-highlight --variable highlightjs=1 --variable theme=bootstrap --mathjax --variable "mathjax-url=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --include-in-header "C:\Users\chris\AppData\Local\Temp\RtmpKmpkq0\rmarkdown-str7ab8779d3ac2.html"
output file: test.knit.md
Unknown option --embed-resources.
Try pandoc.exe --help for more information.
Error:
! pandoc document conversion failed with error 2
Backtrace:
▆
1. └─rmarkdown::render(...)
2. └─rmarkdown (local) convert(output_file, run_citeproc)
3. └─rmarkdown (local) convert_it(output)
4. └─rmarkdown (local) convert_fun(...)
5. └─rmarkdown:::stop2(...)
Exécution arrêtée
As we can see above Pandoc 2.7.3 is correctly use but --embed-resources
flag is still used. Though we have
https://github.com/rstudio/rmarkdown/blob/8d2d9b844406cbefed31835815964c542f7ff1aa/R/pandoc.R#L846-L849
but this is evaluated when format function are evaluated https://github.com/rstudio/rmarkdown/blob/8d2d9b844406cbefed31835815964c542f7ff1aa/R/html_document_base.R#L42-L48
https://github.com/rstudio/rmarkdown/blob/8d2d9b844406cbefed31835815964c542f7ff1aa/R/render.R#L474-L484
So it is too soon for the change of pandoc version to happen in the setup chunk. That is why rmarkdown::pandoc_available("2.19")
returns TRUE (on a system where 3.1.2 is available)
So we should
- Either put any pandoc args conditional to version into
pre_processor
step - Either disallow any change in Pandoc version during rmarkdown rendering (we could track version before knitr and after knitr)
The second case would be breaking change. The first seems fine to me.
Weirdly, no one reported. So should not be that often. But I hit that when debugging pagedown and this when changing pandoc version is useful.