0

I am unable to replace text in a footnote (I can replace body text, and footer, but not in footnotes). Is the officer package unable to replace in footnotes? I am open to work-arounds, other packages, etc.

abc <- "this won't be found in footnote"
read_docx(here::here("report_template.docx")) %>%
  officer::body_replace_text_at_bkm("ftnt_vendor_name", abc) %>%
  print(target = here::here("report_out.docx"))

I get Error: cannot find bookmark "ftnt_vendor_name".

I have also tried replacing text placeholder (not a bookmark), which also doesn't work in my footnote.

abc <- "this won't be found in footnote"
read_docx(here::here("report_template.docx")) %>%
  officer::body_replace_all_text("vendor_name", abc) %>%
  print(target = here::here("report_out.docx"))

I get Found 0 instances of 'vendor_name' in the document.

I have also tried 'slip_in_footnote` which I've never used before. I don't know how to get it to go where I want it (as opposed to the very end), and since playing with it, now I get the error that it can't move the cursor forward.

bl <- block_list(fpar(ftext(abc)))
read_docx(here::here("6. Report", "test.docx")) %>%
  officer::body_add_par("Add footnote here", style = "Normal") %>%
  # officer::cursor_bookmark(id = "add_ftnt02") %>%
  officer::slip_in_footnote(blocks = bl) %>%    #, pos = "after") %>%
  print(target = here::here("6. Report", "test_out.docx"))

I get Error: cannot move forward the cursor as there is no more content in this area

This is a simple example of my issue; I need to do this for several footnotes. Any help would be appreciated!

JHawkins
  • 243
  • 1
  • 2
  • 10
  • 1
    That's true, body_replace_all_text is not working in footnote, it is designed to work in body (that's why the name is "body_"). To answer your question, no, the officer package is unable to replace in footnotes. – David Gohel Jul 24 '21 at 13:48
  • Thank you for the confirmation @DavidGohel. I had a feeling it wasn't possible. Now, I just need to get `slip_in_footnote` to work instead! – JHawkins Jul 26 '21 at 15:41

0 Answers0