The add_plots()
function in the reportifyr
package parses a Microsoft Word document (.docx
file) for predefined magic strings, and inserts corresponding figures from a specified directory.
add_plots()
R: Inserts Figures in appropriate places in a Microsoft Word...
Description
Reads in a .docx
file and returns a new version with figures placed at appropriate places in the document.
Usage
add_plots(
docx_in,
docx_out,
figures_path,
fig_width = NULL,
fig_height = NULL,
debug = FALSE
)
Arguments
docx_in
The file path to the input .docx
file.
docx_out
The file path to the output .docx
file to save to.
figures_path
The file path to the figures directory.
fig_width
A global controller. The figure width in inches. Default is NULL
. If NULL
, the width is determined by the figure's pixel dimensions.
fig_height
A global controller. The figure height in inches. Default is NULL
. If NULL
, the height is determined by the figure's pixel dimensions.
debug
Debug.
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.
# `add_tables()` will format and insert tables into the `.docx` file.
# ---------------------------------------------------------------------------
add_tables(
docx_in = doc_dirs$doc_in,
docx_out = doc_dirs$doc_tables,
tables_path = tables_path
)
# ---------------------------------------------------------------------------
# Step 2.
# Next we insert the plots using the `add_plots()` function.
# ---------------------------------------------------------------------------
add_plots(
docx_in = doc_dirs$doc_tables,
docx_out = doc_dirs$doc_tabs_figs,
figures_path = figures_path
)
## End(Not run)
Returns
Updated Document : A new .docx
file with figures inserted at the appropriate positions.
Time taken by the function:
Logging
Debug : Logs the start and end of the function and if the debug
argument is TRUE
.
Info : Logs docx_in
validation, set figure dimensions, and stdout
, stderr
and status
on succcessful execution of processx::run()
Error : Logs errors for missing docx_in
, issues with docx_in
and/or docx_out
file extensions, and any errors returned from processx::run()
.
Additional Resources
reportifyr GitHub : Refer to the reportifyr
repository for more details.
processx Reference Manual : Refer to the processx
reference manual for specific inquiries related to processx
.
Initialize Report Project Reference : Refer to the reference on initialize_report_project()
here .
Make Doc Dirs Reference : Refer to the reference on make_doc_dirs()
here .
Write Object Metadata Reference : Refer to the reference on write_object_metadata()
here .