wigglesthe3rd
wigglesthe3rd

Reputation: 91

How to delete specific slides on officer?

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)

Upvotes: 1

Views: 112

Answers (1)

MrFlick
MrFlick

Reputation: 206207

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.

Upvotes: 2

Related Questions