1

I'm reading in some slides that are no longer useful/necessary.

I know that with remove_slide allows me to remove a specific slide, but it doesn't allow for the ability to put a list starting from slide 3 to the last one. i.e.

remove_slide(trimmed_ppt, 3:8)

Searching, I was able to find something similar to what I need, but this deletes everything

for (n in rev(seq_len(length(trimmed_ppt)))) {
  remove_slide(trimmed_ppt, index = n)
}

Would there be anyway to adjust the loop or have something that deletes every slide except the first 2 which I need?

for refrence Removing slides of a presentation using officer package in R

Update: Worked out a way I can get what I want. Written terribly, but gets the job done. Had to move slide I wanted to prevent it from getting deleted then placed it back since deleting happens in order. Hope this helps someone.

slides = 6:6

trimmed_ppt = read_pptx(path = "test.pptx")

move_slide(trimmed_ppt, index = 1, to = 8)
walk(rep(1, min(slides)), ~remove_slide(trimmed_ppt, index = .))
move_slide(trimmed_ppt, index = 1, to = 2)

trimmed_ppt %>% 
  write_ppt(report_quarter = report_quarter)

1 Answers1

2

I would guess you could just do

for (n in rev(3:8)) {
  remove_slide(trimmed_ppt, index = n))
}

It would be easier to test with a reproducible example.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • This so much cleaner. In cases like this it's hard to give a reprex, what would you recommend in my approach to similar questions? – wigglesthe3rd May 11 '23 at 18:48
  • 1
    Often the help pages for packages include reproducible examples or sample data that that can be used in your question. That's usually a good place to start. Or write some code that would generate a sample document. – MrFlick May 11 '23 at 19:43