I understand how to explicitly create and use parameters in R Markdown. I have a report with multiple output formats. At render time, I would like to know which output format is current target. Output format does not show up in params
, but, following the DRY principle, I'd like to avoid adding an second, explicit parameter for this. Does anyone know a way to access output format at render time?
Asked
Active
Viewed 60 times
2

jennybryan
- 2,606
- 2
- 18
- 33
-
How is the output format actually selected? The `output_format` option of `rmarkdown::render`, or are you using knitr? `rmarkdown::all_output_formats` would normally work, but I'm not sure it would here. – alistaire Sep 04 '16 at 01:13
-
You should be able to dynamically determine the target output with `knitr::opts_knit$get("rmarkdown.pandoc.to")`. (Assuming I have understood your question ) – Benjamin Sep 04 '16 at 02:47
-
1This may be relevant? http://stackoverflow.com/questions/35144130/in-knitr-how-can-i-test-for-if-the-output-will-be-pdf-or-word/35149103 – Benjamin Sep 04 '16 at 02:50
-
The question (and accepted answer) you link to @Benjamin is spot on. So this should probably be marked as duplicate and linked to that. – jennybryan Sep 04 '16 at 03:15
-
@jennybryan I blogged about this a while back: https://trinkerrstuff.wordpress.com/2014/11/18/rmarkdown-alter-action-depending-on-document/ – Tyler Rinker Sep 04 '16 at 05:28
-
Thanks @TylerRinker. Nice! – jennybryan Sep 04 '16 at 19:39