The build_report() function in the reportifyr package is a wrapper around several reportifyr functions. It parses a Microsoft Word document (.docx file) for predefined magic strings, removes any existing reportifyr tables, figures and footnotes, and inserts up-to-date versions of the tables, figures, and footnotes from file.
build_report()
R: Updates a Microsoft Word file to include formatted plots,...
build_report
R Documentation
Description
Reads in a .docx file and returns a new version with plots, tables, and footnotes replaced.
The file path to the output .docx file to save to. Default is NULL.
figures_path
The file path to the figures and associated metadata directory.
tables_path
The file path to the tables and associated metadata directory.
standard_footnotes_yaml
The file path to the standard_footnotes.yaml. Default is NULL. If NULL, a default standard_footnotes.yaml bundled with the reportifyr package is used.
add_footnotes
A boolean indicating whether to insert footnotes into the docx_in or not. Default is TRUE.
include_object_path
A boolean indicating whether to include the file path of the figure or table in the footnotes. Default is FALSE.
footnotes_fail_on_missing_metadata
A boolean indicating whether to stop execution if the metadata .json file for a figure or table is missing. Default is TRUE.
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_footnotes_yaml
)
## End(Not run)
Returns
Updated Document: A new .docx file with up-to-date tables, figures, and footnotes inserted at the appropriate positions.
Time taken by the function:
0.715 sec elapsed
0.115 sec elapsed
0.275 sec elapsed
Logging
Debug: Logs the start and end of the function.
Info: Logs docx_out validation and migration of intermediate documents to the intermediate_files directory.
Error: Logs errors for missing docx_in, if docx_in and docx_out are the same file, issues with docx_in and/or docx_out file extensions, and any errors returned from add_footnotes().
Additional Resources
reportifyr GitHub: Refer to the reportifyrrepository for more details.
Add Footnotes Reference: Refer to the reference on add_footnotes()here.
Add Plots Reference: Refer to the reference on add_plots()here.
Add Tables Reference: Refer to the reference on add_tables()here.
Make Doc Dirs Reference: Refer to the reference on make_doc_dirs()here.
Remove Tables, Figures, and Footnotes Reference: Refer to the reference on remove_tables_figures_footnotes()here.