The finalize_document() function in the reportifyr package is used to finalize a Microsoft Word document by removing all bookmarks and reportifyr magic strings.
finalize_document()
R: Finalizes the Microsoft Word file by removing magic strings...
finalize_document
R Documentation
Description
Reads in a .docx file and returns a finalized version with magic strings and bookmarks removed.
Usage
finalize_document(docx_in, docx_out = NULL)
Arguments
docx_in
The file path to the input .docx file.
docx_out
The file path to the output .docx file to save to. Default is NULL. If NULL, docx_out is assigned doc_dirs$doc_final using make_doc_dirs(docx_in = docx_in).
Examples
## Not run:
# ---------------------------------------------------------------------------
# Load all dependencies
# ---------------------------------------------------------------------------
docx_in <- here::here("report", "shell", "template.docx")
doc_dirs <- make_doc_dirs(docx_in = docx_in)
figures_path <- here::here("OUTPUTS", "figures")
tables_path <- here::here("OUTPUTS", "tables")
standard_footnotes_yaml <- here::here("report", "standard_footnotes.yaml")
# ---------------------------------------------------------------------------
# Step 1.
# Run the `build_report()` wrapper function to replace figures, tables, and
# footnotes in a `.docx` file.
# ---------------------------------------------------------------------------
build_report(
docx_in = doc_dirs$doc_in,
docx_out = doc_dirs$doc_draft,
figures_path = figures_path,
tables_path = tables_path,
standard_footnotes_yaml = standard_footnote_yaml
)
# ---------------------------------------------------------------------------
# Step 2.
# If you are ready to finalize the `.docx` file, run the `finalize_document()`
# function. This will remove the ties between reportifyr and the document, so
# please be mindful!
# ---------------------------------------------------------------------------
finalize_document(
docx_in = doc_dirs$doc_draft,
docx_out = doc_dirs$doc_final
)
## End(Not run)
Returns
Finalized Document: A finalized .docx file with bookmarks and magic strings removed.
A finalized docx_out is only provided if the user answers Y to the following prompts:
This will remove the bookmarks in the document. This severs the link between the document and reportifyr. Are you sure you want to continue? [Y/n]
This will remove magic strings from the document. This severs link between the document and reportifyr. Are you sure you want to continue? [Y/n]
Logging
Debug: Logs the start and end of the function, as well as the removal of the intermediate document.
Info: Logs provided paths for docx_in, docx_out, and the intermediate document.
Error: Logs errors for missing docx_in, if docx_in and docx_out are the same file, and issues with docx_in and/or docx_out file extensions.
Additional Resources
reportifyr GitHub: Refer to the reportifyrrepository for more details.
Make Doc Dirs Reference: Refer to the reference on make_doc_dirs()here.