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 layout_dedupe_ph_labels() to hanble duplicate placholder labels (close #589) #594

Merged

Conversation

markheckmann
Copy link
Contributor

@markheckmann markheckmann commented Aug 29, 2024

Closes #589.

Building on the suggestions by @Majid-Eismann, I added layout_dedupe_ph_labels() to handle duplicate placholder labels in layouts. By default, it will detect duplicate ph labels, but apply no changes. With action = "rename", it auto-renames duplicate ph labels and action = "delete" deletes them, only keeping their first occurence. If requested, output is printed to the console, informing the user about the changes applied to the placeholder labels. I also added the sample PPTX file ph_dupes.pptx with some duplicate placeholder labels (see code below).

Tests are included. The added file ppt_ph_dedupe_layout.R has 100% coverage increasing the total coverage to 85.4%


Examples

Code from layout_dedupe_ph_labels() docs.

x <- read_pptx()
layout_dedupe_ph_labels(x)

No duplicate placeholder labels detected. 
file <- system.file("doc_examples", "ph_dupes.pptx", package = "officer")
x <- read_pptx(file)
layout_dedupe_ph_labels(x)

Placeholders with duplicate labels:
* 'ph_label_new' = new placeholder label for action = 'rename'
* 'delete_flag' = deleted placeholders for action = 'delete'
  master_name layout_name  ph_label ph_label_new delete_flag
1     Master1     2-dupes Content 7  Content 7.1       FALSE
2     Master1     2-dupes Content 7  Content 7.2        TRUE
layout_dedupe_ph_labels(x, "rename", print_info = TRUE)

Renamed duplicate placeholder labels:
* 'ph_label_new' = new placeholder label
  master_name layout_name  ph_label ph_label_new
1     Master1     2-dupes Content 7  Content 7.1
2     Master1     2-dupes Content 7  Content 7.2

PS. In case of squashing commits, please ensure that @Majid-Eismann's commit also gets credits. :)

majideismann and others added 3 commits August 28, 2024 18:14
…ohel#589)

Building on the code by @Majid-Eismann, I added `layout_dedupe_ph_labels()`
to handle duplicate placholder labels. By default, it will only detect duplicate
labels, but apply no changes. With `action = "rename"`, it auto-renames duplicate
labels and `action = "delete"` deletes duplicates, only keeping their first
occurence. If requested, output is printed to the console, informing the user
about the changes applied to the placeholder labels.
Test coverage for new file is 100%, increasing total
coverage to 85.4%
@davidgohel
Copy link
Owner

In case of squashing commits, please ensure that @Majid-Eismann's commit also gets credits. :)

I am going to "squash and merge" and then I will add you and Majid-Eismann as contributor

@davidgohel davidgohel merged commit 70bf887 into davidgohel:master Aug 29, 2024
3 checks passed
@markheckmann markheckmann deleted the issue_589_duplicate_ph_labels branch August 30, 2024 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove duplicated layout placeholder(s)
2 participants