Is there a way using officer to update an existing table of contents and table of tables with in my document? I know about the function body_add_toc()
but is there a way to update these elements without having to recreate them?

- 25,071
- 21
- 34
- 43

- 689
- 3
- 11
2 Answers
No, TOC is beeing computed by Word. R does not know what content goes in what page. From what I know, the only way to achieve that would be a VBS Macro.

- 9,180
- 2
- 16
- 34
-
Thanks David that makes sense, I will rethink my set up in that case. Thanks for all your work, your packages have been a life saver. – Jordan Hackett Apr 24 '20 at 16:08
As far as I'm aware David is correct.
If you need to automate this process you can use the update_toc(x)
function found in the officerWinTools
R package.
The officerWinTools
R package requires a Windows operating system with Microsoft Office installed (the functions of this package rely upon VBScript ran in Command Prompt).
The update_toc(x)
function is also embedded in the print_docx_pdf(x, target = "path")
function which will export a document created with the officer
R package as a .PDF
to a given path.
You can install the officerWinTools
R package from GitHub:
devtools::install_github("joshmire/officerWinTools")
Also, shout outs to David; your R packages have made my work much less of a headache.

- 736
- 1
- 6
- 17