问题
I'm using body_replace_all_text()
function from officer
package to find and replace some tags in a word document.
The behavior of the body_replace_all_text()
function is unpredictable, working on some of the tags, but not on all of them.
It's also weird that cursor_reach()
functions find the tag, but body_replace_all_text()
can't.
Let's assume we have a simple word document, named "test.docx" with just these two tags:
#KS_STAT#
#TAG#
doc_file <- read_docx("test.docx")
doc_file %>%
body_replace_all_text("#KS_STAT#", toString(Sys.Date())) %>%
body_replace_all_text("#TAG#", "Test Value", fixed = TRUE) %>%
print(target = "test_1.docx")
It's expected to replace both tags, but instead return these error messages:
Warning messages:
1: In x$doc_obj$replace_all_text(old_value, new_value, only_at_cursor, :
Found 0 instances of '#KS_STAT#' in the document.
2: In x$doc_obj$replace_all_text(old_value, new_value, only_at_cursor, :
Found 0 instances of '#TAG#' in the document.
来源:https://stackoverflow.com/questions/57713748/unpredictable-behavior-using-regex-and-body-replace-all-text-in-officer-package