简体   繁体   中英

Error when using function that wraps around ph_with_vg_at

I'm getting the following error when using the officer function ph_with_vg_at:

Error in dml_pptx(file = dml_file, width = width, height = height, offx = left, : argument "height" is missing, with no default

I think the issue is the "funWorkaround" wrapper that I'm using in place of ph_with_vg_at. This function ensures that certain characters are encoded properly when writing to PPT (stole this function here ). I don't get the error when I use ph_with_vg_at instead of funWorkaround.

This was all working perfectly until today, when I updated all of my packages. So not sure if this is an officer/rvg issue or maybe a piping issue. Or none of the above!

I'm looking to either resolve this error or find another way to preserve character encoding when writing from R to PPT. Thanks!

funWorkaround <- function(x, code, left, top, height, width, ...) {
  # Re-Store old encoding on end
  sOldEnc <- getOption("encoding")
  on.exit(options(encoding=sOldEnc))

  # Modify encoding
  options(encoding="UTF-8")

  # Create plot
  return(ph_with_vg_at(x, code, left, top, height, width, ...))
}

ppt_test <- ppt_test %>% 
  add_slide(layout = "Two Content", master = "Office Theme") %>% 
  ph_with_text(type = "title", str = "Satisfaction with Issue Details") %>% 
  funWorkaround(code = print(issuedetails.plot), 
                left = 0.46, 
                top = 2, 
                width = 11.8, 
                height = 4.71)

Solved this by going back to using the straight ph_with_vg_at function instead of the funWorkaround wrapper. To make sure I get the right connection encoding, I put the following at the start of my deck creation script:

oldEnc = getOption("encoding") options(encoding = "UTF-8")

Then I put this at the end of the script:

options(encoding = oldEnc)

This moves the connection settings to UTF-8 while building the PPT but then ensures that it returns to original native.enc once the PPT file is built. Otherwise, you might run into unforeseen issues (like reading data) if the setting remains in UTF-8.

Are you using a later version of the rvg package? There's a new argument ggobj which is the 3rd argument by default. If you simply name the arguments in your workaround, it should work:

funWorkaround <- function(x, code, left, top, height, width, ...) {
  # Re-Store old encoding on end
  sOldEnc <- getOption("encoding")
  on.exit(options(encoding=sOldEnc))

  # Modify encoding
  options(encoding="UTF-8")

  # Create plot
  return(ph_with_vg_at(x, code=code, left=left, top=top, height=height, width=width, ...))
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM