A couple years ago I wrote a post on how to "mail merge" an Excel table in PowerPoint; i.e., create slides based on information in each row of an Excel table.
Occasionally I am asked how to do something similar with slides containing images. I figured R Markdown might be a good tool for this.
Let's say I have this below data frame.
slides <- data.frame(Name = c("Jack", "Joe", "Susan", "Hetta"), Hometown = c("New York", "Philadelphia", "Boston", "Berlin"), Headshot = c("H:/slides/jack.jpg", "H:/slides/joe.jpg", "H:/slides/susan.jpg", "H:/slides/hetta.jpg"))
I want to create a slide for each row of the data frame in the style of:
### Name - Hometown !(Headshot)
Any thoughts? What I ended up doing for now is to paste the fields that I need together with R Markdown styling into a new column and paste that output into a
.rmd file (like below) but I would think there's a much more efficient solution here.
I suppose this would be something like a loop but I'm not familiar with how they work to generate text in R Markdown.
slides$md <- paste0("### Name: ", slides$Name, "\n - Hometown: ", slides$Hometown, "\n\n !(", slides$Headshot, ")\n\n --- \n\n") cat(slides$md)
### Name: Jack - Hometown: New York !(H:/slides/jack.jpg) --- ### Name: Joe - Hometown: Philadelphia !(H:/slides/joe.jpg) --- ### Name: Susan - Hometown: Boston !(H:/slides/susan.jpg) --- ### Name: Hetta - Hometown: Berlin !(H:/slides/hetta.jpg) ---