| Title: | Reproducible Reporting Made Simple with R |
|---|---|
| Description: | Create reproducible reports with Microsoft Word and R. |
| Authors: | Jacob Dumbleton [aut, cre], Matthew Smith [aut], Theodoros Papathanasiou [aut], Tarjinder Sahota [aut], Devin Pastoor [aut], Agnes Kim [aut], Anne Zheng [aut], Jenna Johnson [aut], Fernando Carreno [aut], Kashyap Patel [ctb], Maxwell Chirehwa [ctb], Wesley Cummings [ctb], Elizabeth LeBeau [ctb] |
| Maintainer: | Jacob Dumbleton <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.4.0 |
| Built: | 2026-09-27 10:56:47 UTC |
| Source: | https://github.com/a2-ai/reportifyr |
Reads in a .docx file and returns a new version with footnotes placed at appropriate places in the document.
add_footnotes( docx_in, docx_out, figures_path, tables_path, standard_footnotes_yaml = NULL, config_yaml = NULL, include_object_path = FALSE, footnotes_fail_on_missing_metadata = TRUE, debug = FALSE )add_footnotes( docx_in, docx_out, figures_path, tables_path, standard_footnotes_yaml = NULL, config_yaml = NULL, include_object_path = FALSE, footnotes_fail_on_missing_metadata = TRUE, debug = FALSE )
docx_in |
The file path to the input |
docx_out |
The file path to the output |
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 |
config_yaml |
The file path to the |
include_object_path |
A boolean indicating whether to include the file path of the figure or table in the footnotes. Default is |
footnotes_fail_on_missing_metadata |
A boolean indicating whether to stop execution if the metadata |
debug |
Debug. |
## 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)## 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)
Reads in a .docx file and returns a new version with figures placed at appropriate places in the document.
add_plots( docx_in, docx_out, figures_path, config_yaml = NULL, fig_width = NULL, fig_height = NULL, debug = FALSE )add_plots( docx_in, docx_out, figures_path, config_yaml = NULL, fig_width = NULL, fig_height = NULL, debug = FALSE )
docx_in |
The file path to the input |
docx_out |
The file path to the output |
figures_path |
The file path to the figures directory. |
config_yaml |
The file path to the |
fig_width |
A global controller. The figure width in inches. Default is |
fig_height |
A global controller. The figure height in inches. Default is |
debug |
Debug. |
## 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)## 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)
Inserts alt text for figures within a Microsoft Word file.
add_plots_alt_text(docx_in, docx_out, figures_path = NULL, debug = FALSE)add_plots_alt_text(docx_in, docx_out, figures_path = NULL, debug = FALSE)
docx_in |
The file path to the input |
docx_out |
The file path to the output |
figures_path |
The file path to the figures directory. Used to embed artifact hashes in alt text. Default is |
debug |
Debug. |
## Not run: add_plots_alt_text("doc-figs.docx", "doc-draft.docx") ## End(Not run)## Not run: add_plots_alt_text("doc-figs.docx", "doc-draft.docx") ## End(Not run)
Reads in a .docx file and returns a new version with tables placed at appropriate places in the document.
add_tables(docx_in, docx_out, tables_path, config_yaml = NULL, debug = FALSE)add_tables(docx_in, docx_out, tables_path, config_yaml = NULL, debug = FALSE)
docx_in |
The file path to the input |
docx_out |
The file path to the output |
tables_path |
The file path to the tables and associated metadata directory. |
config_yaml |
The file path to the |
debug |
Debug. |
## 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)## 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)
Inserts alt text for tables within a Microsoft Word file.
add_tables_alt_text(docx_in, docx_out, tables_path = NULL, debug = FALSE)add_tables_alt_text(docx_in, docx_out, tables_path = NULL, debug = FALSE)
docx_in |
The file path to the input |
docx_out |
The file path to the output |
tables_path |
The file path to the tables directory. Used to embed artifact hashes in alt text. Default is |
debug |
Debug. |
## Not run: add_tables_alt_text("document-tabs.docx", "document-tabs_at.docx") ## End(Not run)## Not run: add_tables_alt_text("document-tabs.docx", "document-tabs_at.docx") ## End(Not run)
Reads in a .docx file and returns a new version with plots, tables, and footnotes replaced.
build_report( docx_in, docx_out = NULL, figures_path, tables_path, standard_footnotes_yaml = NULL, config_yaml = NULL, add_footnotes = TRUE, include_object_path = FALSE, footnotes_fail_on_missing_metadata = TRUE )build_report( docx_in, docx_out = NULL, figures_path, tables_path, standard_footnotes_yaml = NULL, config_yaml = NULL, add_footnotes = TRUE, include_object_path = FALSE, footnotes_fail_on_missing_metadata = TRUE )
docx_in |
The file path to the input |
docx_out |
The file path to the output |
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 |
config_yaml |
The file path to the |
add_footnotes |
A boolean indicating whether to insert footnotes into the |
include_object_path |
A boolean indicating whether to include the file path of the figure or table in the footnotes. Default is |
footnotes_fail_on_missing_metadata |
A boolean indicating whether to stop execution if the metadata |
## 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)## 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)
Reads in a .docx file and returns a finalized version with magic strings and bookmarks removed.
finalize_document(docx_in, docx_out = NULL, config_yaml = NULL)finalize_document(docx_in, docx_out = NULL, config_yaml = NULL)
docx_in |
The file path to the input |
docx_out |
The file path to the output |
config_yaml |
The file path to the |
## 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 ) # --------------------------------------------------------------------------- # 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)## 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 ) # --------------------------------------------------------------------------- # 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)
Searches upward from start_path for a reportifyr init file
(e.g., .report_init.json). Returns the directory containing
the init file, or NULL if none is found.
find_project_root(start_path = getwd())find_project_root(start_path = getwd())
start_path |
Path to start searching from. Defaults to the current working directory. |
Absolute path to the project root directory,
or NULL if no init file is found.
## Not run: find_project_root() ## End(Not run)## Not run: find_project_root() ## End(Not run)
Autofits a flextable object, then fits the object to the page width
fit_flextable_to_page(ft, page_width = 6)fit_flextable_to_page(ft, page_width = 6)
ft |
A flextable object |
page_width |
The width of page in inches |
A flextable object fit to page
## Not run: # Load libary for examples: library(flextable) # Create a flextable object and fit to default page width: ft <- flextable(iris) fit_flextable_to_page(ft) # Create a flextable object and specify page width to fit to: ft <- flextable(iris) fit_flextable_to_page(ft, page_width = 6.5) ## End(Not run)## Not run: # Load libary for examples: library(flextable) # Create a flextable object and fit to default page width: ft <- flextable(iris) fit_flextable_to_page(ft) # Create a flextable object and specify page width to fit to: ft <- flextable(iris) fit_flextable_to_page(ft, page_width = 6.5) ## End(Not run)
Formats data frames to a flextable specification
format_flextable(data_in, table1_format = FALSE)format_flextable(data_in, table1_format = FALSE)
data_in |
The input data to be formatted. Must be either a data frame or a flextable object. |
table1_format |
A boolean indicating whether to apply table1-style formatting. Default is |
A formatted flextable
## Not run: dt <- head(iris, 10) format_flextable( data_in = dt ) ## End(Not run)## Not run: dt <- head(iris, 10) format_flextable( data_in = dt ) ## End(Not run)
Format a one-line summary of a reportifyr context
## S3 method for class 'rpfy_context' format(x, ...)## S3 method for class 'rpfy_context' format(x, ...)
x |
An |
... |
Unused. |
Character scalar suitable for logging.
Get the current log file path
get_log_file()get_log_file()
path to the log file, or NULL if not set
Get meta abbreviations from standard_footnotes.yaml
get_meta_abbrevs(path_to_footnotes_yaml)get_meta_abbrevs(path_to_footnotes_yaml)
path_to_footnotes_yaml |
The file path to the |
A list of meta_abbrevs to be called while performing an analysis
## Not run: standard_footnotes_yaml <- here::here("report", "standard_footnotes.yaml") meta_abbrevs <- get_meta_abbrevs(path_to_footnotes_yaml = standard_footnotes_yaml) ## End(Not run)## Not run: standard_footnotes_yaml <- here::here("report", "standard_footnotes.yaml") meta_abbrevs <- get_meta_abbrevs(path_to_footnotes_yaml = standard_footnotes_yaml) ## End(Not run)
Get meta types from standard_footnotes.yaml
get_meta_type(path_to_footnotes_yaml)get_meta_type(path_to_footnotes_yaml)
path_to_footnotes_yaml |
The file path to the |
A list of meta_type to be called while performing an analysis
## Not run: standard_footnotes_yaml <- here::here("report", "standard_footnotes.yaml") meta_type <- get_meta_type(path_to_footnotes_yaml = standard_footnotes_yaml) ## End(Not run)## Not run: standard_footnotes_yaml <- here::here("report", "standard_footnotes.yaml") meta_type <- get_meta_type(path_to_footnotes_yaml = standard_footnotes_yaml) ## End(Not run)
Deprecated; forwards to pyro::get_venv_uv_paths(). Prefer
pyro::get_venv_uv_paths() in new code.
get_venv_uv_paths()get_venv_uv_paths()
list of paths to uv and venv directory for calling py scripts
## Not run: get_venv_uv_paths() ## End(Not run)## Not run: get_venv_uv_paths() ## End(Not run)
Extension to the ggsave() function that allows capturing object metadata as a separate .json file.
ggsave_with_metadata( filename, plot = ggplot2::last_plot(), meta_type = "NA", meta_equations = NULL, meta_notes = NULL, meta_abbrevs = NULL, config_yaml = NULL, context = NULL, ... )ggsave_with_metadata( filename, plot = ggplot2::last_plot(), meta_type = "NA", meta_equations = NULL, meta_notes = NULL, meta_abbrevs = NULL, config_yaml = NULL, context = NULL, ... )
filename |
The filename for the plot to save to. |
plot |
The plot object to save. Default is the last displayed plot ( |
meta_type |
A string to specify the type of object. Default is |
meta_equations |
A string or vector of strings representing equations to include in the metadata. Default is |
meta_notes |
A string or vector of strings representing notes to include in the metadata. Default is |
meta_abbrevs |
A string or vector of strings representing abbreviations
to include in the metadata. Default is |
config_yaml |
The file path to the |
context |
An |
... |
Additional arguments passed to the
|
## Not run: # --------------------------------------------------------------------------- # Construct and save a simple ggplot # --------------------------------------------------------------------------- g <- ggplot2::ggplot( data = Theoph, ggplot2::aes(x = Time, y = conc, group = Subject) ) + ggplot2::geom_point() + ggplot2::geom_line() + ggplot2::theme_bw() # Save a png using the wrapper function figures_path <- here::here("OUTPUTS", "figures") plot_file_name <- "01-12345-pk-timecourse1.png" ggsave_with_metadata(filename = file.path(figures_path, plot_file_name)) ## End(Not run)## Not run: # --------------------------------------------------------------------------- # Construct and save a simple ggplot # --------------------------------------------------------------------------- g <- ggplot2::ggplot( data = Theoph, ggplot2::aes(x = Time, y = conc, group = Subject) ) + ggplot2::geom_point() + ggplot2::geom_line() + ggplot2::theme_bw() # Save a png using the wrapper function figures_path <- here::here("OUTPUTS", "figures") plot_file_name <- "01-12345-pk-timecourse1.png" ggsave_with_metadata(filename = file.path(figures_path, plot_file_name)) ## End(Not run)
This function is deprecated; it forwards to
pyro::initialize_python(). The Python environment (uv, Python
interpreter, pinned dependencies) is owned by the pyro package;
call pyro::initialize_python() directly in new code.
initialize_python(continue = NULL)initialize_python(continue = NULL)
continue |
Optional argument to bypass asking user for confirmation to install python deps. |
invisibly the metadata_file path
## Not run: initialize_python() ## End(Not run)## Not run: initialize_python() ## End(Not run)
Create report directories within a project
initialize_report_project( project_dir, report_dir_name = NULL, outputs_dir_name = NULL )initialize_report_project( project_dir, report_dir_name = NULL, outputs_dir_name = NULL )
project_dir |
The file path to the main project directory where the directory structure will be created. The directory must already exist; otherwise, an error will be thrown. |
report_dir_name |
The directory name for where reports will be saved.
Default is |
outputs_dir_name |
The directory name for where artifacts will be saved.
Default is |
## Not run: initialize_report_project(project_dir = tempdir()) ## End(Not run)## Not run: initialize_report_project(project_dir = tempdir()) ## End(Not run)
Helper function that defines document output paths
make_doc_dirs(docx_in)make_doc_dirs(docx_in)
docx_in |
The file path to the input |
A list of document paths
## Not run: # --------------------------------------------------------------------------- # Load all dependencies # --------------------------------------------------------------------------- docx_in <- here::here("report", "shell", "template.docx") doc_dirs <- make_doc_dirs(docx_in = docx_in) ## End(Not run)## Not run: # --------------------------------------------------------------------------- # Load all dependencies # --------------------------------------------------------------------------- docx_in <- here::here("report", "shell", "template.docx") doc_dirs <- make_doc_dirs(docx_in = docx_in) ## End(Not run)
Previews a single metadata file for an object
preview_metadata(file_name)preview_metadata(file_name)
file_name |
The file path of the file whose metadata you want to preview. |
A single row data frame consisting of metadata type and footnotes for the object supplied
## Not run: figures_path <- here::here("OUTPUTS", "figures") plot_file_name <- "myplot.png" preview_metadata(file.path(figures_path, plot_file_name)) ## End(Not run)## Not run: figures_path <- here::here("OUTPUTS", "figures") plot_file_name <- "myplot.png" preview_metadata(file.path(figures_path, plot_file_name)) ## End(Not run)
Preview all metadata .json files in a directory
preview_metadata_files(file_dir)preview_metadata_files(file_dir)
file_dir |
The file path to a directory containing metadata .json files. |
A data frame of metadata footnotes and meta type
## Not run: figures_path <- here::here("OUTPUTS", "figures") preview_metadata_file(figures_path) ## End(Not run)## Not run: figures_path <- here::here("OUTPUTS", "figures") preview_metadata_file(figures_path) ## End(Not run)
Print a reportifyr context
## S3 method for class 'rpfy_context' print(x, ...)## S3 method for class 'rpfy_context' print(x, ...)
x |
An |
... |
Unused. |
The context invisibly.
Reads in a .docx file and returns a new version with tables, figures, and footnotes removed from the document.
remove_tables_figures_footnotes( docx_in, docx_out, config_yaml = NULL, figures_path = NULL, tables_path = NULL )remove_tables_figures_footnotes( docx_in, docx_out, config_yaml = NULL, figures_path = NULL, tables_path = NULL )
docx_in |
The file path to the input |
docx_out |
The file path to the output |
config_yaml |
The file path to the |
figures_path |
The file path to the figures directory. Used for hash-based skip of unchanged artifacts. Default is |
tables_path |
The file path to the tables directory. Used for hash-based skip of unchanged artifacts. Default is |
## Not run: # --------------------------------------------------------------------------- # Load all dependencies # --------------------------------------------------------------------------- docx_in <- here::here("report", "shell", "template.docx") doc_dirs <- make_doc_dirs(docx_in = docx_in) # --------------------------------------------------------------------------- # Removing tables, figures, and footnotes # --------------------------------------------------------------------------- remove_tables_figures_footnotes( docx_in = doc_dirs$doc_in, docx_out = doc_dirs$doc_clean ) ## End(Not run)## Not run: # --------------------------------------------------------------------------- # Load all dependencies # --------------------------------------------------------------------------- docx_in <- here::here("report", "shell", "template.docx") doc_dirs <- make_doc_dirs(docx_in = docx_in) # --------------------------------------------------------------------------- # Removing tables, figures, and footnotes # --------------------------------------------------------------------------- remove_tables_figures_footnotes( docx_in = doc_dirs$doc_in, docx_out = doc_dirs$doc_clean ) ## End(Not run)
This pacakge aims to ease table, figure, and footnote insertion and formatting into reports.
initialize_report_project: Creates report directory
with shell, draft, scripts, final subdirectories and adds
standard_footnotes.yaml to /report directory.
Initializes python virtual environment through a subcall to
initialize_python
creates OUTPUTS/figures, OUTPUTS/tables, OUTPUTS/listings directories
initialize_python: Creates virtual environment in
options("venv_dir") if set or project root otherwise.
Also installs python-docx and pyyaml packages.
ggsave_with_metadata: Wrapper for saving ggplot that
also creates metadata for plot object
save_rds_with_metadata: Wrapper for saveRDS that also
creates metadata for tabular object and saves as rtf
write_csv_with_metadata: Wrapper for write.csv that
also creates metadata for tabular object and saves as rtf
format_flextable: Formats a tabular data object as a
flextable with simple formatting.
write_object_metadata: Creates a metadata.json file for
the input object path. Called within all analysis output saving functions.
update_object_footnotes: Used to update footnotes fields
within object metadata json files.
preview_metadata_files: Generates a data frame of all
object metadata within input directory and displays object, meta type, equations
notes, abbreviations.
preview_metadata: Generates the metadata data frame of the
singular input file.
get_meta_type: Generates meta_type object to allow user to
see available meta_types in standard_footnotes.yaml within report directory
get_meta_abbrevs: Generates meta_abbrev object to allow user
to see available abbreviations in standard_footnotes.yaml within report directory.
add_tables: Adds tables into the word document
add_footnotes: Adds footnotes for figures and tables
add_plots: Adds plots into the word document
remove_tables_figures_footnotes: Removes all tables,
figures, and footnotes associated with a magic string {rpfy}:object.ext
remove_magic_strings: Removes all magic strings from a
document cutting its tie to reportifyr but producing a final document.
remove_bookmarks: Removes all bookmarks from document
build_report: Wrapper function to remove old tables,
figures, and footnotes and adds new ones. Calls
remove_tables_figures_footnotes, make_doc_dirs,
add_plots, add_tables, add_footnotes
finalize_document: Wrapper function to remove magic
strings and bookmarks from document.
make_doc_dirs: FILL IN
fit_flextable_to_page: FILL IN
validate_object: FILL IN
validate_config: FILL IN
Maintainer: Jacob Dumbleton [email protected]
Authors:
Matthew Smith [email protected]
Theodoros Papathanasiou [email protected]
Tarjinder Sahota [email protected]
Devin Pastoor [email protected]
Agnes Kim [email protected]
Anne Zheng [email protected]
Jenna Johnson [email protected]
Fernando Carreno [email protected]
Other contributors:
Kashyap Patel [email protected] [contributor]
Maxwell Chirehwa [email protected] [contributor]
Wesley Cummings [email protected] [contributor]
Elizabeth LeBeau [email protected] [contributor]
Useful links:
Captures session-level metadata once so that it can be
reused across many *_with_metadata() wrapper calls without
recomputing on every artifact. Construct the context at the top
of a script or Shiny app and pass it via the context argument
to ggsave_with_metadata(), save_rds_with_metadata(),
write_csv_with_metadata(), or write_object_metadata().
rpfy_context(origin = NULL, addl_metadata = NULL)rpfy_context(origin = NULL, addl_metadata = NULL)
origin |
Controls what is recorded in
|
addl_metadata |
Optional named list of caller-supplied
provenance tags, written under the |
An object of class rpfy_context — a list with fields
system_meta, source_meta, addl_metadata, author,
project_root.
## Not run: ctx <- rpfy_context( origin = shiny_source("myapp"), addl_metadata = list(analyst = "jake", study = "PK-001") ) print(ctx) validate_rpfy_context(ctx) ggsave_with_metadata("plot.png", context = ctx, meta_type = "efficacy") ## End(Not run)## Not run: ctx <- rpfy_context( origin = shiny_source("myapp"), addl_metadata = list(analyst = "jake", study = "PK-001") ) print(ctx) validate_rpfy_context(ctx) ggsave_with_metadata("plot.png", context = ctx, meta_type = "efficacy") ## End(Not run)
Extension to the saveRDS() function that allows capturing object metadata as a separate .json file.
save_rds_with_metadata( object, file = "", config_yaml = NULL, meta_type = "NA", meta_equations = NULL, meta_notes = NULL, meta_abbrevs = NULL, table1_format = FALSE, context = NULL, ... )save_rds_with_metadata( object, file = "", config_yaml = NULL, meta_type = "NA", meta_equations = NULL, meta_notes = NULL, meta_abbrevs = NULL, table1_format = FALSE, context = NULL, ... )
object |
The |
file |
The connection or name of the file where the |
config_yaml |
The file path to the |
meta_type |
A string to specify the type of object. Default is |
meta_equations |
A string or vector of strings representing equations to include in the metadata. Default is |
meta_notes |
A string or vector of strings representing notes to include in the metadata. Default is |
meta_abbrevs |
A string or vector of strings representing abbreviations to include in the metadata. Default is |
table1_format |
A boolean indicating whether to apply table1-style formatting. Default is |
context |
An |
... |
Additional arguments passed to the |
## Not run: # --------------------------------------------------------------------------- # Save a simple table # --------------------------------------------------------------------------- tables_path <- here::here("OUTPUTS", "tables") outfile_name <- "01-12345-pk-theoph.RDS" save_rds_with_metadata( object = Theoph, file = file.path(tables_path, outfile_name) ) ## End(Not run)## Not run: # --------------------------------------------------------------------------- # Save a simple table # --------------------------------------------------------------------------- tables_path <- here::here("OUTPUTS", "tables") outfile_name <- "01-12345-pk-theoph.RDS" save_rds_with_metadata( object = Theoph, file = file.path(tables_path, outfile_name) ) ## End(Not run)
source value for an artifact produced from a scriptReturns a classed list suitable for the origin
argument of rpfy_context(). Typically produced internally by
rpfy_context() via auto-detection; exposed for callers that want
to stamp a known script identity. The type discriminator is not
stored on the list; it is emitted at serialization time so the
class is the single source of truth.
script_source(path, creation_author, latest_author, creation_time, latest_time)script_source(path, creation_author, latest_author, creation_time, latest_time)
path |
Character scalar. Path to the source script, relative to the project root. |
creation_author |
Character scalar. Git author of the first commit touching the script. |
latest_author |
Character scalar. Git author of the most recent commit touching the script. |
creation_time |
Character scalar. Timestamp of the first commit. |
latest_time |
Character scalar. Timestamp of the most recent commit. |
A named list with creation_author, latest_author, path,
creation_time, and latest_time elements, classed as
c("script_source", "rpfy_source_meta").
## Not run: src <- script_source( path = "scripts/01-pk.R", creation_author = "jake", latest_author = "jake", creation_time = "2026-01-01 00:00:00", latest_time = "2026-04-20 12:00:00" ) ctx <- rpfy_context(origin = src) ## End(Not run)## Not run: src <- script_source( path = "scripts/01-pk.R", creation_author = "jake", latest_author = "jake", creation_time = "2026-01-01 00:00:00", latest_time = "2026-04-20 12:00:00" ) ctx <- rpfy_context(origin = src) ## End(Not run)
source value for an artifact produced from a Shiny appReturns a classed list suitable for the origin
argument of rpfy_context(). The type discriminator is not
stored on the list; it is emitted at serialization time so the
class is the single source of truth.
shiny_source(app_name, app_version = NULL)shiny_source(app_name, app_version = NULL)
app_name |
Character scalar. Name of the installed R package that is the Shiny app. |
app_version |
Optional character scalar version. When |
A named list with app_name and app_version elements,
classed as c("shiny_source", "rpfy_source_meta").
## Not run: ctx <- rpfy_context(origin = shiny_source("myapp")) ggsave_with_metadata( filename = "OUTPUTS/figures/plot.png", context = ctx ) ## End(Not run)## Not run: ctx <- rpfy_context(origin = shiny_source("myapp")) ggsave_with_metadata( filename = "OUTPUTS/figures/plot.png", context = ctx ) ## End(Not run)
config.yaml against the
.<report>_init.json snapshot. Always runs
pyro::initialize_python(groups = "reportifyr"); prompts the
user only when the project .venv is missing, otherwise runs
non-interactively (a no-op when uv reports no work needed).Synchronizes report project with the bundled pyro Python
environment and reconciles the report config.yaml against the
.<report>_init.json snapshot. Always runs
pyro::initialize_python(groups = "reportifyr"); prompts the
user only when the project .venv is missing, otherwise runs
non-interactively (a no-op when uv reports no work needed).
sync_report_project(project_dir, report_dir_name = NULL)sync_report_project(project_dir, report_dir_name = NULL)
project_dir |
The file path to the main project directory where the directory structure will be created. The directory must already exist; otherwise, an error will be thrown. |
report_dir_name |
The directory name for where reports will be saved.
Default is |
## Not run: sync_report_project(here::here()) ## End(Not run)## Not run: sync_report_project(here::here()) ## End(Not run)
options(rpfy.no_log = TRUE) to suppress file logging for the
session (console output is unaffected).Updates the logging level for console output. Default is set to WARN.
File logging is always at DEBUG level when log_file is provided. Set
options(rpfy.no_log = TRUE) to suppress file logging for the
session (console output is unaffected).
toggle_logger(quiet = FALSE, log_file = get_log_file(), lazy_file = FALSE)toggle_logger(quiet = FALSE, log_file = get_log_file(), lazy_file = FALSE)
quiet |
suppresses messaging about log level. |
log_file |
path to log file. Defaults to the current session log file
set on package load. Use |
lazy_file |
if TRUE, delay log file creation until first log write. |
## Not run: Sys.setenv("RPFY_VERBOSE" = "DEBUG") toggle_logger() ## End(Not run)## Not run: Sys.setenv("RPFY_VERBOSE" = "DEBUG") toggle_logger() ## End(Not run)
Updates an object's footnote metadata - equations, notes, or abbreviations
update_object_footnotes( file_path, overwrite = FALSE, meta_equations = NULL, meta_notes = NULL, meta_abbrevs = NULL )update_object_footnotes( file_path, overwrite = FALSE, meta_equations = NULL, meta_notes = NULL, meta_abbrevs = NULL )
file_path |
The file path to the object or its metadata file. |
overwrite |
A boolean indicating whether to overwrite existing metadata entries. Default is |
meta_equations |
A string or vector of strings representing equations to include or overwrite in the metadata. |
meta_notes |
A string or vector of strings representing notes to include or overwrite in the metadata. |
meta_abbrevs |
A string or vector of strings representing abbreviations to include or overwrite in the metadata. |
## Not run: update_object_footnotes("example_metadata.json", equations = c("K10 = CL/VC", "K12 = Q/VC")) ## End(Not run)## Not run: update_object_footnotes("example_metadata.json", equations = c("K10 = CL/VC", "K12 = Q/VC")) ## End(Not run)
Validate alt text of figures/tables against their magic strings in a Microsoft Word file
validate_alt_text_magic_strings(docx_in, debug = FALSE)validate_alt_text_magic_strings(docx_in, debug = FALSE)
docx_in |
The file path to the input |
debug |
Debug. |
## Not run: validate_alt_text_magic_strings("template.docx") ## End(Not run)## Not run: validate_alt_text_magic_strings("template.docx") ## End(Not run)
Validate config.yaml file
validate_config(path_to_config_yaml)validate_config(path_to_config_yaml)
path_to_config_yaml |
The file path to the |
bool TRUE if config is valid, FALSE otherwise.
## Not run: validate_config(here::here("report/config.yaml")) ## End(Not run)## Not run: validate_config(here::here("report/config.yaml")) ## End(Not run)
Validates input Microsoft Word file to ensure proper functionality with reportifyr
validate_docx(docx_in, config_yaml)validate_docx(docx_in, config_yaml)
docx_in |
The file path to the input |
config_yaml |
The file path to the |
## Not run: validate_docx( here::here("report/shell/template.docx"), here::here("report/config.yaml") ) ## End(Not run)## Not run: validate_docx( here::here("report/shell/template.docx"), here::here("report/config.yaml") ) ## End(Not run)
Validates a file's hash against a stored hash in the associated _metadata.json file
validate_object(file)validate_object(file)
file |
The connection or name of the file where the |
A boolean declaring if the hashes are equal or not
## Not run: tables_path <- here::here("OUTPUTS", "tables") outfile_name <- "01-12345-pk-theoph.csv" validate_object(file = file.path(tables_path, out_name)) ## End(Not run)## Not run: tables_path <- here::here("OUTPUTS", "tables") outfile_name <- "01-12345-pk-theoph.csv" validate_object(file = file.path(tables_path, out_name)) ## End(Not run)
Checks that an rpfy_context has the expected fields
and that each field holds a valid value. Errors on any problem.
validate_rpfy_context(context)validate_rpfy_context(context)
context |
An |
The context invisibly.
script_source objectErrors if x is not a script_source or if any of
path, creation_author, latest_author, creation_time,
latest_time are not non-empty character scalars.
validate_script_source(x)validate_script_source(x)
x |
A |
x invisibly.
shiny_source objectErrors if x is not a shiny_source or if
app_name / app_version are not non-empty character scalars.
validate_shiny_source(x)validate_shiny_source(x)
x |
A |
x invisibly.
Extension to the write.csv() function that allows capturing object metadata as a separate .json file.
write_csv_with_metadata( object, file, config_yaml = NULL, meta_type = "NA", meta_equations = NULL, meta_notes = NULL, meta_abbrevs = NULL, table1_format = FALSE, context = NULL, ... )write_csv_with_metadata( object, file, config_yaml = NULL, meta_type = "NA", meta_equations = NULL, meta_notes = NULL, meta_abbrevs = NULL, table1_format = FALSE, context = NULL, ... )
object |
The |
file |
The connection or name of the file where the |
config_yaml |
The file path to the |
meta_type |
A string to specify the type of object. Default is |
meta_equations |
A string or vector of strings representing equations to include in the metadata. Default is |
meta_notes |
A string or vector of strings representing notes to include in the metadata. Default is |
meta_abbrevs |
A string or vector of strings representing abbreviations to include in the metadata. Default is |
table1_format |
A boolean indicating whether to apply table1-style formatting. Default is |
context |
An |
... |
Additional arguments passed to the |
## Not run: # --------------------------------------------------------------------------------- # Save a simple table # --------------------------------------------------------------------------------- tables_path <- here::here("OUTPUTS", "tables") outfile_name <- "01-12345-pk-theoph.csv" write_csv_with_metadata( object = Theoph, file = file.path(tables_path, out_name), row_names = FALSE ) ## End(Not run)## Not run: # --------------------------------------------------------------------------------- # Save a simple table # --------------------------------------------------------------------------------- tables_path <- here::here("OUTPUTS", "tables") outfile_name <- "01-12345-pk-theoph.csv" write_csv_with_metadata( object = Theoph, file = file.path(tables_path, out_name), row_names = FALSE ) ## End(Not run)
Writes an object's metadata .json file
write_object_metadata( object_file, meta_type = NULL, meta_equations = NULL, meta_notes = NULL, meta_abbrevs = NULL, table1_format = FALSE, context = NULL )write_object_metadata( object_file, meta_type = NULL, meta_equations = NULL, meta_notes = NULL, meta_abbrevs = NULL, table1_format = FALSE, context = NULL )
object_file |
The file path of the object to write metadata for. |
meta_type |
A string to specify the type of object. Default is |
meta_equations |
A string or vector of strings representing equations to include in the metadata. Default is |
meta_notes |
A string or vector of strings representing notes to include in the metadata. Default is |
meta_abbrevs |
A string or vector of strings representing abbreviations to include in the metadata. Default is |
table1_format |
A boolean indicating whether table1 formatting is used for |
context |
An |
## Not run: figures_path <- here::here("OUTPUTS", "figures") plot_file_name <- "01-12345-pk-timecourse1.png" write_object_metadata(object_file = file.path(figures_path, plot_file_name)) ## End(Not run)## Not run: figures_path <- here::here("OUTPUTS", "figures") plot_file_name <- "01-12345-pk-timecourse1.png" write_object_metadata(object_file = file.path(figures_path, plot_file_name)) ## End(Not run)