-
Notifications
You must be signed in to change notification settings - Fork 107
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
Comments
thanks, I can reproduce From
There is an issue with |
That worked! Thank you so much! |
AnalysisThe reason is that the master slide is empty. It has no objects (shapes, pics, images etc. on it). (NB: Also first the slide layout has not objects on it.) Now, when loading the PPTX via obj$slideLayouts <- dir_layout$new( package_dir,
master_metadata = obj$masterLayouts$get_metadata(),
master_xfrm = obj$masterLayouts$xfrm() ) The reason is, that the xfrm = function(){
nodeset <- xml_find_all( self$get(), as_xpath_content_sel("p:cSld/p:spTree/") )
read_xfrm(nodeset, self$file_name(), self$name())
} However, as there are no objects in the master slide,
xfrmize <- function(slide_xfrm, master_xfrm) {
x <- as.data.frame(slide_xfrm)
master_ref <- unique(data.frame(
file = master_xfrm$file,
master_name = master_xfrm$name,
stringsAsFactors = FALSE
))
master_xfrm <- fortify_master_xfrm(master_xfrm) SuggestionI tried catching the edge case by adding the following to read_xfrm <- function(nodeset, file, name){
if( length(nodeset) < 1 && !( is.na(name) || is.null(name)) ) {
return(data.frame(stringsAsFactors = FALSE,
type = NA_character_,
id = NA_character_,
ph_label = NA_character_,
ph = NA_character_,
file = basename(file),
offx = NA_integer_,
offy = NA_integer_,
cx = NA_integer_,
cy = NA_integer_,
rotation = NA_integer_,
name = name,
fld_id = NA_character_,
fld_type = NA_character_
))
} However, I do not really oversee the consequences of this and one test also fails. I think having zero objects on a master is quite a rare edge case. The simplest would be simply to warn the user in this case. @davidgohel What do you think? |
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
The text was updated successfully, but these errors were encountered: