0

I would like to select a table from a PowerPoint presentation, and later loop this to pull data from the table in each week's PowerPoint presentation.

However, the slide which contains the table of interest shifts slightly throughout one year's worth of data. Thus instead of selecting the table using the slide number/ ID, I'd like to select the table using the slide title as that will remain consistent with the table of interest, even if the slide ID changes.

How would one select the slide using a title that contains "measles surveillance" and "2018" ?

zero323
  • 322,348
  • 103
  • 959
  • 935
mgdixon
  • 1
  • 1
  • When asking a question about a problem caused by your code, you will get much better answers if you provide code people can use to reproduce the problem. https://stackoverflow.com/help/mcve – simanacci Nov 07 '18 at 18:45

1 Answers1

0

Try something like:

library(officer)
library(tidyverse)

doc <- read_pptx("your-spiffy-slides.pptx")

pb <- progress_estimated(length(doc))
map_df(seq_along(doc), ~{
  pb$tick()$print()
  slide_summary(on_slide(doc, .x)) %>% 
    mutate(slide_no = .x)
}) -> slides_df

slides_df will — amongst other elements — contain the slide number (slide_no) and a text column. You can look for your target text in the text column and then associate the slide number with it.

Some decks are YUGE hence the progress bar (that is not a requirement but can help pass the time if you do have YUGE decks).

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
  • So what I really want to do is pull out a table on a slide with the title "X". What would be the code for that? – mgdixon Nov 08 '18 at 19:48
  • the code provided gives you the text on every slide with the field it is in. you just need to filter on that, get the page, go to that slide and then pull your table. – hrbrmstr Nov 08 '18 at 20:15