You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
library(officer)
# Default pptx templatex<- 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 duplicatedx#> 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_2x<-x|> add_slide("Title Slide") # unique, no master requiredx<-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")
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:
Keep current behavior, despite NULLvalue for layout for the default template and note this in the docs
Use a general rule to use the 1st layout if the arg is NULL
Create a layout_default() function, which allows users to set a default layout for the rpptx object.
Instruct user to use a custom wrapper, e.g. add_my_slide <- \(x, layout = "Title and Content", master = NULL) add_slide(x, layout, master)
The text was updated successfully, but these errors were encountered:
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
Currently,
add_slide()
has default values for thelayout
andmaster
args.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
master
arg default toNULL
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 thelayout
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
Created on 2025-02-16 with reprex v2.0.2
2) set
layout
arg default toNULL
The current default
layout
("Title and Content") only makes sense when using the default pptx template. I would suggest to change this toNULL
, 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:NULL
value forlayout
for the default template and note this in the docsNULL
layout_default()
function, which allows users to set a default layout for therpptx
object.add_my_slide <- \(x, layout = "Title and Content", master = NULL) add_slide(x, layout, master)
The text was updated successfully, but these errors were encountered: