Skip to content

Add Footnotes

The add_footnotes() function in the reportifyr package parses a Microsoft Word document (.docx file) for predefined magic strings, and inserts corresponding footnotes.


add_footnotes()

R: Inserts Footnotes in appropriate places in a Microsoft Word...
add_footnotesR Documentation

Description

Reads in a .docx file and returns a new version with footnotes placed at appropriate places in the document.

Usage

add_footnotes(
  docx_in,
  docx_out,
  figures_path,
  tables_path,
  standard_footnotes_yaml = NULL,
  include_object_path = FALSE,
  footnotes_fail_on_missing_metadata = TRUE,
  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 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.

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.

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
)

# ---------------------------------------------------------------------------
# Step 3.
# Now we can add the footnotes with the `add_footnotes` function.
# ---------------------------------------------------------------------------
add_footnotes(
  docx_in = doc_dirs$doc_tabs_figs,
  docx_out = doc_dirs$doc_draft,
  figures_path = figures_path,
  tables_path = tables_path,
  standard_footnotes_yaml = standard_footnotes_yaml,
  include_object_path = FALSE,
  footnotes_fail_on_missing_metadata = TRUE
)

## End(Not run)

Returns

  • Updated Document: A new .docx file with footnotes inserted at the appropriate positions.

Time taken by the function:

0.335 sec elapsed

Logging

  • Debug: Logs the start and end of the function, the start and end of each processx::run(), and if the debug argument is TRUE.
  • Info: Logs docx_in and metadata .json validation and stdout, stderr and status on succcessful execution of each processx::run()
  • Warning: Logs the stderr if processx:run() returns a non-zero character.
  • Error: Logs errors for missing docx_in, missing virtual environment (venv_path), 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.