diff --git a/DESCRIPTION b/DESCRIPTION index ee3009cb..4a72e2a5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: officer Title: Manipulation of Microsoft Word and PowerPoint Documents -Version: 0.6.7.014 +Version: 0.6.7.015 Authors@R: c( person("David", "Gohel", , "david.gohel@ardata.fr", role = c("aut", "cre")), person("Stefan", "Moog", , "moogs@gmx.de", role = "aut"), diff --git a/R/ppt_ph_dedupe_layout.R b/R/ppt_ph_dedupe_layout.R index b486cde4..ab6edae4 100644 --- a/R/ppt_ph_dedupe_layout.R +++ b/R/ppt_ph_dedupe_layout.R @@ -73,7 +73,8 @@ layout_dedupe_ph_labels <- function(x, action = "detect", print_info = FALSE) { if (xfrm$delete_flag[i]) { xml2::xml_remove(shape) } else { - xml2::xml_find_first(shape, ".//p:cNvPr") |> xml2::xml_set_attr("name", xfrm$ph_label_new[i]) + nodes <- xml2::xml_find_first(shape, ".//p:cNvPr") + xml2::xml_set_attr(nodes, "name", xfrm$ph_label_new[i]) } } layout$save() # persist changes in slideout xml file @@ -118,7 +119,7 @@ has_ph_dupes <- function(x) { return(invisible(NULL)) } .df_2 <- x$slideLayouts$get_xfrm_data() - .df_2 <- .df_2[, c("master_file", "master_name"), drop = FALSE] |> unique() + .df_2 <- unique(.df_2[, c("master_file", "master_name"), drop = FALSE]) df <- merge(.df_1, .df_2, sort = FALSE) rownames(df) <- NULL df <- df[, c("master_name", "name", "ph_label", "ph_label_new", "delete_flag"), drop = FALSE] diff --git a/R/pptx_layout_helper.R b/R/pptx_layout_helper.R index 679109a5..30f3579a 100644 --- a/R/pptx_layout_helper.R +++ b/R/pptx_layout_helper.R @@ -50,17 +50,6 @@ get_layout <- function(x, layout, master = NULL) { } - -# else { -# # multiple layouts -# layout_exists(x, layout, must_exist = TRUE) -# layout_is_unique(x, layout, require_unique = TRUE) -# index <- which(df$layout_name == layout) -# } -# index <- which(df$layout_name == layout) -# l <- df[index, ] |> as.list() -# # l <- c(index = index, l, slide_layout = slide_layout) - #' @export print.layout_info <- function(x, ...) { cli::cli_h3("{.cls layout_info} object") diff --git a/R/utils.R b/R/utils.R index a97ae660..cf69f6dc 100644 --- a/R/utils.R +++ b/R/utils.R @@ -263,7 +263,8 @@ is_doc_open <- function(file) { # get_file_index(files) # get_file_index <- function(file) { - sub(pattern = ".+?(\\d+).xml$", replacement = "\\1", x = basename(file), ignore.case = TRUE) |> as.numeric() + x <- sub(pattern = ".+?(\\d+).xml$", replacement = "\\1", x = basename(file), ignore.case = TRUE) + as.numeric(x) } diff --git a/tests/testthat/test-pptx-add.R b/tests/testthat/test-pptx-add.R index 79bbc63b..10a275f4 100644 --- a/tests/testthat/test-pptx-add.R +++ b/tests/testthat/test-pptx-add.R @@ -349,40 +349,40 @@ test_that("pptx ph_location_type", { on.exit(options(opts)) x <- read_pptx() - x <- x |> add_slide("Two Content") + x <- add_slide(x, "Two Content") expect_no_error({ - x |> ph_with("correct ph type id", ph_location_type("body", type_idx = 1)) + ph_with(x, "correct ph type id", ph_location_type("body", type_idx = 1)) }) expect_warning({ - x |> ph_with("cannot supply id AND type_idx", ph_location_type("body", type_idx = 1, id = 1)) + ph_with(x, "cannot supply id AND type_idx", ph_location_type("body", type_idx = 1, id = 1)) }, regexp = "`id` is ignored if `type_idx` is provided", fixed = TRUE) expect_warning({ - x |> ph_with("id still working with warning to avoid breaking change", ph_location_type("body", id = 1)) + ph_with(x, "id still working with warning to avoid breaking change", ph_location_type("body", id = 1)) }, regexp = "The `id` argument in `ph_location_type()` is deprecated", fixed = TRUE) expect_error({ - x |> ph_with("out of range type id", ph_location_type("body", type_idx = 3)) # 3 does not exists => no error or warning + ph_with(x, "out of range type id", ph_location_type("body", type_idx = 3)) # 3 does not exists => no error or warning }, regexp = "`type_idx` is out of range.", fixed = TRUE) expect_error({ expect_warning({ - x |> ph_with("out of range type id", ph_location_type("body", id = 3)) # 3 does not exists => no error or warning + ph_with(x, "out of range type id", ph_location_type("body", id = 3)) # 3 does not exists => no error or warning }, regexp = " The `id` argument in `ph_location_type()` is deprecated", fixed = TRUE) }, regexp = "`id` is out of range.", fixed = TRUE) expect_error({ - x |> ph_with("type okay but not available in layout", ph_location_type("tbl")) # tbl not on layout + ph_with(x, "type okay but not available in layout", ph_location_type("tbl")) # tbl not on layout }, regexp = "Found no placeholder of type", fixed = TRUE) expect_error({ - x |> ph_with("xxx is unknown type", ph_location_type("xxx")) + ph_with(x, "xxx is unknown type", ph_location_type("xxx")) }, regexp = 'type "xxx" is unknown', fixed = TRUE) expect_no_error({ # for complete coverage - x |> ph_with(" ph type position_right", ph_location_type("body", position_right = TRUE)) + ph_with(x, " ph type position_right", ph_location_type("body", position_right = TRUE)) }) }) @@ -416,11 +416,11 @@ test_that("pptx ph_location_id", { # downstream errors x <- read_pptx() - x <- x |> add_slide("Comparison") + x <- add_slide(x, "Comparison") expect_error( { - x |> ph_with("id does not exist", ph_location_id(id = 1000)) + ph_with(x, "id does not exist", ph_location_id(id = 1000)) }, "`id` 1000 does not exist", fixed = TRUE @@ -430,7 +430,7 @@ test_that("pptx ph_location_id", { expect_no_error({ ids <- layout_properties(x, "Comparison")$id for (id in ids) { - x |> ph_with(paste("text:", id), ph_location_id(id, newlabel = paste("newlabel:", id))) + ph_with(x, paste("text:", id), ph_location_id(id, newlabel = paste("newlabel:", id))) } }) nodes <- xml_find_all(