Is it possible to put an 'if' statement into an RMarkdown file? I have to produce two documents which have the same content, but use different PowerPoint template files (different backgrounds/images/fonts/etc). I am struggling to find a way to do this with minimal code. It seems that YAML doesn't have an 'if' function due to its nature. The alternative is to set a variable in the main R script, and then try and use that in the Rmd file YAML:
reference_doc: "`r ref_doc`"
However, this doesn't work - it just gets passed as-is to the pandoc command:
"C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/pandoc" +RTS -K512m -RTS My_Data_Pack.knit.md --to pptx --from markdown+autolink_bare_uris+tex_math_single_backslash --output pandoc54e45caae7a.pptx --reference-doc "`r ref_doc`"
Another alternative I tried was having two different files with hard-coded YAML files, and then pulling all of the common R Markdown code in from another file:
---
title: "`r pres_title`"
author: Me
output:
powerpoint_presentation:
reference_doc: "`r ref_doc`"
date: "`r format(Sys.Date(), '%d %B %Y')`"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(ggplot2)
library(ggrepel)
library(knitr)
library(tidyr)
library(flextable)
library(ggpubr)
library(forcats)
library(zoo)
set_flextable_defaults(
font.family = "Arial", font.size = 8.5,
border.color = "gray", big.mark = "")
source("main_output_stuff.R")
But that doesn't work, because main_output_stuff.R isn't a proper R file, and that's sort of inherently not how the system was built to work.
Is there an easy way to do what I want? Or indeed a not-easy way?
Many thanks.