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

master_name appear as NA in read_pptx, resulting in 'attempt to apply non-function' error on ph_with #488

Open
csbu00 opened this issue Apr 6, 2023 · 2 comments
Labels

Comments

@csbu00
Copy link

csbu00 commented Apr 6, 2023

I created a simple slide template with a master template and several layouts, along with their placeholder (attached). Oddly, when I try to read_pptx, it seems to not be picking up the master template's name (it's reading as a null value)? This seems to result in error when using ph_with - I'm guessing it's because it couldn't process a null value. Have I perhaps done something wrong, either in the template creation or code, or is this a bug? Thank you!

Slide Template_R.pptx

library('tidyverse')
library('officer')

presentation <- officer::read_pptx('Slide Template_R.pptx')
template_object_map <- presentation %>% officer::layout_properties() %>% select(c('master_name','name', 'type', 'id', 'ph_label')) 

my_pres <- presentation %>% 
			remove_slide(index = 1) %>% 
			add_slide(master=NA, layout='Style_leftright_a') %>%
			ph_with(value= 'Corridors', location = ph_location_label(ph_label = "Big Title")) 
@davidgohel
Copy link
Owner

thanks, I can reproduce

From presentation |> layout_summary(), I can see your master is named 'Custom Design', you can use the following code

library('tidyverse')
library('officer')

presentation <- officer::read_pptx('~/Downloads/Slide.Template_R (1).pptx')
template_object_map <- presentation %>% officer::layout_properties() %>% select(c('master_name','name', 'type', 'id', 'ph_label'))

my_pres <- presentation %>%
  remove_slide(index = 1) %>%
  add_slide(master='Custom Design', layout='Style_leftright_a') %>%
  ph_with(value= 'Corridors', location = ph_location_label(ph_label = "Big Title"))

print(my_pres, target = "Custom Design.pptx")

There is an issue with template_object_map <- presentation %>% officer::layout_properties() that should not gives you NA. Thanks for reporting

@davidgohel davidgohel added the bug label Apr 6, 2023
@csbu00
Copy link
Author

csbu00 commented Apr 6, 2023

That worked! Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants