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

feat: change defaults of master and layout arg in add_slide() #635

Open
markheckmann opened this issue Feb 16, 2025 · 0 comments
Open

feat: change defaults of master and layout arg in add_slide() #635

markheckmann opened this issue Feb 16, 2025 · 0 comments

Comments

@markheckmann
Copy link
Contributor

markheckmann commented Feb 16, 2025

Currently, add_slide() has default values for the layout and masterargs.

  • This only works well when using the default pptx template but fails if a custom pptx file is used.
  • In many cases, the master arg is reduntant and could be omitted.

I suggest to set both to NULL as a default. Details below.

@davidgohel , please let me know what you think :)


1) set masterarg default to NULL

If there is only one master, there is no ambiguity regarding the layout name (enforced to be unique per master by PowerPoint). Hence, master is not needed and could be optional. The same applies in case of several masters if the layout name is unique across masters. Also, the current default master only works for the default pptx template.

It would look like this for custom_pptx.pptx

library(officer)

# Default pptx template
x <- read_pptx()
x <- x |> add_slide("Title Slide")
x <- x |> add_slide("Title and Content")

file <- tempfile(fileext = ".pptx")
download.file("https://github.com/user-attachments/files/18814735/custom_pptx.pptx", file)
x <- read_pptx(file)

# Custom pptx template with 2 masters.
# - Layout "Title Slide" occurs in one master and is unique
# - Layout "Title and Content" occurs in both masters and is duplicated
x
#> pptx document with 0 slide(s)
#> Available layouts and their associated master(s) are:
#>              layout   master
#> 1       Title Slide Master_1
#> 2 Title and Content Master_1
#> 3 Title and Content Master_2

x <- x |> add_slide("Title Slide") # unique, no master required
x <- x |> add_slide("Title and Content") # not unique, requires master arg
#> Error:
#> ! Layout exists in more than one master
#> ✖ Please specify the master name in arg `master`
x <- x |> add_slide("Title and Content", "Master_2")

Created on 2025-02-16 with reprex v2.0.2

2) set layout arg default to NULL

The current default layout ("Title and Content") only makes sense when using the default pptx template. I would suggest to change this to NULL, as it currently does not conform the general case, i.e. arbitrary pptx templates.

If one would still like to preserve the feature to call add_slide() without any arguments, as currently possible with the default pptx template, there would be several ways to do so:

  1. Keep current behavior, despite NULLvalue for layout for the default template and note this in the docs
  2. Use a general rule to use the 1st layout if the arg is NULL
  3. Create a layout_default() function, which allows users to set a default layout for the rpptx object.
  4. Instruct user to use a custom wrapper, e.g. add_my_slide <- \(x, layout = "Title and Content", master = NULL) add_slide(x, layout, master)
@markheckmann markheckmann changed the title feat: change defaults of master and layout arg in add_slide() feat: change defaults of master and layout arg in add_slide() Feb 16, 2025
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

No branches or pull requests

1 participant