0

I'm using flextable and officer to write tables to powerpoints that have hyperlinked cells. When a URL has an & in it, though, the & gets replaced with &. It still works in the flextable in the viewer of my RStudio window, but changes when I export to powerpoint. Here's an example (with a fake link to illustrate what's happening):

library(officer)
library(flextable)
library(magrittr)

link <- "google.com/fake?action=click&module=Top"
# Make the table
ft <- data.frame(x = "Hello", link = link) %>%
  flextable() %>%
  compose(j = 1, value = as_paragraph(hyperlink_text(x = x, url = link)))
    
# Add to a slide
my_pres <- read_pptx() %>%
  add_slide() %>%
  ph_with(value = ft, location = ph_location_type(type = "body"))

print(my_pres, "~/Desktop/example.pptx")

When I open up the powerpoint, the link has been replaced with: google.com/fake?action=click&amp;module=Top.

I removed and reinstalled officer and flextable, and now the same code produces this link: google.com/fake%3Faction%3Dclick%26module%3DTop. I'm on officer 0.3.17 and flextable 0.6.4.

Is there something going on with the XML that I have to escape to keep the URL the same?

redarah
  • 152
  • 7
  • .pptx is an XML format, isn't it, so surely `&` is the correct representation of an ampersand. – Michael Kay Mar 16 '21 at 19:48
  • This looks like a bug that has been fixed in the latest version. Could you make sure you have the latest version (`>=0.6.4`)? – David Gohel Mar 16 '21 at 20:03
  • Thanks @DavidGohel. I was running on `0.6.4.3`. I removed and re-installed (so now it's `0.6.4`) and I'm still having trouble. This time, the `?` is replaced with `%3F`, the `=` is replaced with `%3D`, and the `&` is replaced with `%26`. Is there another version I should try...? – redarah Mar 17 '21 at 13:45
  • BTW, you link is invalid, it should be "https://google.com/fake?action=click&module=Top" – David Gohel Mar 17 '21 at 14:22
  • When I click on the link in presentation mode, it open the correct link, are you saying this is not ok on your side? – David Gohel Mar 17 '21 at 14:23
  • The replacement is exected, url is encoded to be sure it remains valid – David Gohel Mar 17 '21 at 14:24
  • You're right, thank you! Unfortunately it just comes up as "Invalid Link" in Google Slides, which is why I wish it could just keep the `&` as normal, but you're correct that it's now working okay in Microsoft Powerpoint. So it seems to be an issue with the Powerpoint > Slides transition. Thank you for your help and sorry for the trouble. – redarah Mar 17 '21 at 14:30
  • I'll add that it seems this fix has made all hyperlinks no longer work in Google Slides. When I run on version `0.6.3`, and upload the file to Google Slides, all the hyperlinks without `&` in them work (only the ones with `&` don't) - when I run on `0.6.4` none of the hyperlinks work at all in Slides. I know this package is meant for .pptx, not Google Slides, but as a huge flextable&officer user/superfan who has to share deliverables in Slides, I would so so appreciate the new encoding being an option I could pass as a parameter somewhere, rather than staying pinned to an old version :) – redarah Mar 17 '21 at 14:57

0 Answers0