简体   繁体   中英

Removing slides of a presentation using officer package in R

I am working with officer package in R to transfer my plots as outputs to a power point presentation.

Every time I run the code, I want to make sure that there are no slides in the pptx in which I want to save my plots.

Right now I know how to remove a single slide from the presentation. But I have no idea of how to remove all the slides at once.

My code so far is:

    library(officer)

    # reading template slides and adding slide in which I want my plot 

    doc <- read_pptx("U://30-Power & Water//25 Renewables//WORK//Config//Templates//Template.pptx")

    doc <- add_slide(doc, layout = "Title and Content",master = "Office Theme")
    doc <- ph_with_gg(doc, value = Sweihan ) #plot = ggplot

    # Reading the output slides and removing slides (it is just removing one slide so far)    

    output <- read_pptx("U://30-Power & Water//25 Renewables//WORK//Result//Result.pptx")

    output <-  remove_slide(output)

    print(output, target = "U://30-Power & Water//25 Renewables//WORK//Result//Result.pptx" ) %>% invisible()

    # tranfering results to output ppt file
    print(doc, target = "U://30-Power & Water//25 Renewables//WORK//Result//Result.pptx" ) %>% invisible()

what function can I use in my code using officer package to remove all the slides at once?

Your help will be appreciated!

Regards

The documentation for index argument in remove_slide is

Usage: remove_slide(x, index = NULL)

index - slide index, default to current slide position

Hence, you can remove slide one at a time as follows:

for (n in rev(seq_len(length(output)))) {
    remove_slide(output, n)
}

#show number of slides
length(output)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM