From 88e94bfdf30a0c6f4ad5e0d4d734674fc4e7d415 Mon Sep 17 00:00:00 2001 From: Alan Yeung Date: Fri, 10 Nov 2023 09:53:31 +0000 Subject: [PATCH] escape characters fix --- R/phs_report_docx.R | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/R/phs_report_docx.R b/R/phs_report_docx.R index 29e0446..241c472 100644 --- a/R/phs_report_docx.R +++ b/R/phs_report_docx.R @@ -119,12 +119,21 @@ phs_report_docx <- function(toc = FALSE, officer::body_replace_all_text("Subtitle", stitle) %>% officer::body_replace_all_text("DD Month YYYY", dt) + # Convert characters in output file path that need escaped for XML + xml_elt <- officer::to_wml(officer::block_pour_docx(output_file), + add_ns = TRUE) + + if (grepl("&", output_file)) { + output_escape <- gsub("&", "&", output_file) + xml_elt <- gsub(output_file, output_escape, xml_elt) + } + # Combine Cover and Report cover_page %>% officer::cursor_end() %>% officer::body_remove() %>% officer::body_add_break() %>% - officer::body_add_docx(output_file) %>% + officer::body_add_xml(str = xml_elt) %>% officer::set_doc_properties(title = title) %>% print(output_file) }