1

I want to be able to pass an rpptx object into a function that outputs a character vector of slide layout names for each slide in the object.

For example, using a fictitious get_slide_layouts() function:

pres <- officer::read_pptx()

pres <- officer::add_slide(pres, layout = "Title and Content", master = "Office Theme")
pres <- officer::add_slide(pres, layout = "Title and Content", master = "Office Theme")

get_slide_layouts(pres)

I would be looking for the output:

c("Title and Content", "Title and Content")

slide_summary() doesn't seem to give me what I'm looking for. How can I extract the layout names for each slide in the rpptx object?

Giovanni Colitti
  • 1,982
  • 11
  • 24

1 Answers1

1

Maybe there is an easier way or a convenience function for this task. But one option would be to do:

Note: Basically the approach gets the names by matching filenames from the layouts metadata with the ones from the slide metadata.

pres <- officer::read_pptx()

pres <- officer::add_slide(pres, layout = "Title and Content", master = "Office Theme")
pres <- officer::add_slide(pres, layout = "Title and Content", master = "Office Theme")

get_slide_layouts <- function(x) {
  layouts <- x$slideLayouts$get_metadata()  
  slides <- x$slide$get_metadata()
  
  layouts[match(basename(slides$layout_file), layouts$filename), "name"]
}

get_slide_layouts(pres)
#> [1] "Title and Content" "Title and Content"
stefan
  • 90,330
  • 6
  • 25
  • 51