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

fix: ph_location_type() - throw error for out of range type id (fix #602) and more info if ph type not present (close #601) #603

Conversation

markheckmann
Copy link
Contributor

@markheckmann markheckmann commented Sep 8, 2024

ph_location_type():

  1. now throws an error if the id for a type is out of range. Before, it went unnoticed (no error or warning) and caused a corrupted .pptx file (fix bug: ph_location_type(): generates corrupted .pptx when selecting an id that does exist #602).
  2. generates a more informative error message when the type exists but is not present in the current layout (close feat: issue more informative error if ph label does not exist #601).
  3. error message if the type is unknown was rewritten using cli style message

BEFORE

library(officer)
x <- read_pptx()
x <- x |> add_slide("Two Content")

# 1) id=3 does not exists => no error or warning
x |> ph_with("unknown id", ph_location_type("body", id = 3)) 
pptx document with 1 slide(s)
Available layouts and their associated master(s) are:
             layout       master
1       Title Slide Office Theme
2 Title and Content Office Theme
3    Section Header Office Theme
4       Two Content Office Theme
5        Comparison Office Theme
6        Title Only Office Theme
7             Blank Office Theme

# 2) tbl is allowed type but not present in slide => error code not informative
x |> ph_with("unknown id", ph_location_type("tbl", id = 3))   
Error in get_ph_loc(doc, layout = layout, master = master, type = x$type,  : 
  no selected row

# 3) type is unkown
> x |> ph_with("unknown id", ph_location_type("xxx")) 
Error in ph_location_type("xxx") : 
  argument type ('xxx') expected to be a value of "ctrTitle", "subTitle", "dt", "ftr", "sldNum", "title", "body", "pic", "chart", "tbl", "dgm", "media", "clipArt".

NEW

# 1) generates error now
x |> ph_with("unknown id", ph_location_type("body", id = 3))
Error:
! `id` is out of range.Must be between 1 and 2 for ph type "body".see `layout_properties(x, 'Two Content', 'Office Theme')` for all phs with type 'body'

# 2) more informative error 
x |> ph_with("unknown id", ph_location_type("tbl", id = 3)) 
Error:
! Found no placeholder of type "tbl" on layout "Two Content".Available types are "body", "dt", "ftr", "sldNum", and "title"see `layout_properties(x, 'Two Content', 'Office Theme')`

# 3) error message in cli style
x |> ph_with("unknown id", ph_location_type("xxx")) 
Error:
! type "xxx" is unknown.Must be one of "ctrTitle", "subTitle", "dt", "ftr", "sldNum", "title",
  "body", "pic", "chart", "tbl", "dgm", "media", or "clipArt"

`ph_location_type()` now throws an informative error if ...
- `id` for a `type` is our of range (davidgohel#602)
- type exists but is not present in current layout

also: improved error message if type is unknown
@markheckmann markheckmann changed the title fix: ph_location_type() - error for out of range type id and more info if ph type not present (fix #602) fix: ph_location_type() - error for out of range type id and more info if ph type not present (close #601, fix #602) Sep 8, 2024
@markheckmann markheckmann changed the title fix: ph_location_type() - error for out of range type id and more info if ph type not present (close #601, fix #602) fix: ph_location_type() - error for out of range type id (fix #602) and more info if ph type not present (close #601) Sep 8, 2024
@markheckmann markheckmann changed the title fix: ph_location_type() - error for out of range type id (fix #602) and more info if ph type not present (close #601) fix: ph_location_type() - throw error for out of range type id (fix #602) and more info if ph type not present (close #601) Sep 8, 2024
@davidgohel davidgohel merged commit 0c3fef3 into davidgohel:master Sep 9, 2024
3 checks passed
@markheckmann markheckmann deleted the issue_602_ph_location_type_generates_corrupted_pptx branch September 11, 2024 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants