Skip to content

Add Tables

The add_tables() function in the reportifyr package parses a Microsoft Word document (.docx file) for predefined magic strings, and inserts corresponding tables from a specified directory.


add_tables()

R: Inserts Tables in appropriate places in a Microsoft Word file
add_tablesR Documentation

Description

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

Usage

add_tables(docx_in, docx_out, tables_path, 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.

tables_path

The file path to the tables and associated metadata directory.

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
)

## End(Not run)

Returns

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

Time taken by the function:

0.788 sec elapsed

Logging

  • Debug: Logs the start and end of the function and if the debug argument is TRUE.
  • Info: Logs key function milestones, such as magic string detection, file loading, and table insertions.
  • Warn: Logs when a table or its associated metadata .json files are missing or if magic strings are not found within the docx_in.
  • Error: Logs errors for missing docx_in and issues with docx_in and/or docx_out file extensions.

Additional Resources

  • reportifyr GitHub: Refer to the reportifyr repository for more details.
  • 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.