Context
I perform data analysis primarily in R, and the final output is typically in the form of one or more MS PowerPoint decks that can be shared with non-technical clients for downstream editing. Over the years, I've streamlined my process to the following:
- Preprocess data (clean, merge, etc.) as usual;
- Create a .Rmd file for PowerPoint presentation output (as described here) and add all the code used for generating final outputs there; separate the contents into reasonably-sized pieces such that the text / table / plots in each slide of the outputted file doesn't spill beyond the slide's margins.
- Knit the markdown file into a MS Powerpoint presentation.
I often deal with 50+ slides & 100+ plot outputs, so the time saved thanks to this workflow, where I don't have to insert individual images into a deck of slides (or worse, try to subsequently pinpoint a specific one for tweaks based on client's feedback), is non-trivial.
One particular characteristic of R markdown for PowerPoint is that the hierarchical structure described by #
, ##
, ..., ####
is flattened to two levels: the top level corresponds to slides that serve as section dividers, while the bottom level corresponds to slides for content (typically in one or two columns). I typically specify the division between top & bottom level as 2
, which means a line in the .Rmd file beginning with # blah blah
goes into a section divider slide, while a line beginning with ## blah blah
will go into the header placeholder on a content slide. The following toy example of a .Rmd file illustrates this:
---
title: Title slide (Slide 1)
output:
powerpoint_presentation:
slide_level: 2 # use this to override default
---
# Section header (Slide 2)
Any content here (below a section header & without a slide header preceding it)
will go into a new header-less slide (Slide 3).
## Slide demonstrating markdown syntax (Slide 4)
*italic*, **bold**, ~subscript~, ^superscript^, [small caps]{.smallcaps}, `verbatim`
# A second section header (Slide 5)
## A slide for numbered points (Slide 6)
1. Numbered points
1. In running order
1. No matter what values were provided
## Another slide on bullet points (Slide 7)
- Bullet point 1
- Bullet point 2
Issues
I like to organize my slides into collapsible sections in PowerPoint for my sanity + ease of navigating in slide show mode, but find it cumbersome to do so manually in PowerPoint, every time I knit a file.
The actual template used for section placeholder slides has two placeholders, one meant for header text (which is what
# blah blah
feeds into), and one meant for content text - which currently goes wasted. Since these slides serve as section dividers, I would like the second placeholder to show something like "Section [#]", or "Annex [#]", etc.
Note: I know rmarkdown::powerpoint_presentation()
includes an option for numbered sections, but that adds a section number before EVERY slide header, & I don't necessarily want numbers to increment automatically at slide level.
Desired state
I'd like to have a solution that takes in the result from knitting the R markdown file and automatically processes it to:
split slides into sections based on location of section header slides; and
modify the section header slides to include subtitles of the form "Section XXX".