Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to remove unused media files #571

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Revert rm_images feature for remove_slide
  • Loading branch information
SteffenWolfFA-ERF committed May 6, 2024
commit 659d15bbec56101039283e02cf76e20f32719baf
11 changes: 1 addition & 10 deletions R/pptx_slide_manip.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,14 @@ on_slide <- function(x, index) {
#' @description Remove a slide from a pptx presentation.
#' @param x an rpptx object
#' @param index slide index, default to current slide position.
#' @param rm_images if TRUE (defaults to FALSE), images presented in
#' the slide to remove are also removed from the file.
#' @note cursor is set on the last slide.
#' @examples
#' my_pres <- read_pptx()
#' my_pres <- add_slide(my_pres)
#' my_pres <- remove_slide(my_pres)
#' @family functions slide manipulation
#' @seealso [read_pptx()], [ph_with()], [ph_remove()]
remove_slide <- function(x, index = NULL, rm_images = FALSE) {
remove_slide <- function(x, index = NULL) {
l_ <- length(x)
if (l_ < 1) {
stop("presentation contains no slide to delete", call. = FALSE)
Expand All @@ -113,13 +111,6 @@ remove_slide <- function(x, index = NULL, rm_images = FALSE) {
filename <- basename(x$presentation$slide_data()$target[index])
location <- which(x$slide$get_metadata()$name %in% filename)

if (rm_images) {
media_files <- pptx_summary(x)$media_file
if (length(media_files)) {
unlink(file.path(x$package_dir, media_files), force = TRUE)
}
}

del_file <- x$slide$remove_slide(location)

# update presentation elements
Expand Down