Package 'reportifyr'

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.3.4
Built: 2026-05-21 10:14:54 UTC
Source: https://github.com/a2-ai/reportifyr

Help Index


Inserts Footnotes in appropriate places in a Microsoft Word file

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,
  config_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.

config_yaml

The file path to the config.yaml. Default is NULL, a default config.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)

Inserts Figures in appropriate places in a Microsoft Word file

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,
  config_yaml = NULL,
  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.

config_yaml

The file path to the config.yaml. Default is NULL, a default config.yaml bundled with the reportifyr package is used.

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)

Inserts alt text for figures within a Microsoft Word file.

Description

Inserts alt text for figures within a Microsoft Word file.

Usage

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

debug

Debug.

Examples

## Not run: 
add_plots_alt_text("doc-figs.docx", "doc-draft.docx")

## End(Not run)

Inserts Tables in appropriate places in a Microsoft Word file

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, config_yaml = 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.

tables_path

The file path to the tables and associated metadata directory.

config_yaml

The file path to the config.yaml. Default is NULL, a default config.yaml bundled with the reportifyr package is used.

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)

Inserts alt text for tables within a Microsoft Word file.

Description

Inserts alt text for tables within a Microsoft Word file.

Usage

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

debug

Debug.

Examples

## Not run: 
add_tables_alt_text("document-tabs.docx", "document-tabs_at.docx")

## End(Not run)

Updates a Microsoft Word file to include formatted plots, tables, and footnotes

Description

Reads in a .docx file and returns a new version with plots, tables, and footnotes replaced.

Usage

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
)

Arguments

docx_in

The file path to the input .docx file.

docx_out

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.

config_yaml

The file path to the config.yaml. Default is NULL, a default config.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)

Finalizes the Microsoft Word file by removing magic strings and bookmarks

Description

Reads in a .docx file and returns a finalized version with magic strings and bookmarks removed.

Usage

finalize_document(docx_in, docx_out = NULL, config_yaml = NULL)

Arguments

docx_in

The file path to the input .docx file.

docx_out

The file path to the output .docx file to save to. Default is NULL. If NULL, docx_out is assigned doc_dirs$doc_final using make_doc_dirs(docx_in = docx_in).

config_yaml

The file path to the config.yaml. Default is NULL, a default config.yaml bundled with the reportifyr package is used.

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_footnote_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)

Autofits a flextable object, then fits the object to the page width

Description

Autofits a flextable object, then fits the object to the page width

Usage

fit_flextable_to_page(ft, page_width = 6)

Arguments

ft

A flextable object

page_width

The width of page in inches

Value

A flextable object fit to page

Examples

## 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

Description

Formats data frames to a flextable specification

Usage

format_flextable(data_in, table1_format = FALSE)

Arguments

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 FALSE.

Value

A formatted flextable

Examples

## Not run: 
dt <- head(iris, 10)
format_flextable(
  data_in = dt
)

## End(Not run)

Get meta abbreviations from standard_footnotes.yaml

Description

Get meta abbreviations from standard_footnotes.yaml

Usage

get_meta_abbrevs(path_to_footnotes_yaml)

Arguments

path_to_footnotes_yaml

The file path to the standard_footnotes.yaml file.

Value

A list of meta_abbrevs to be called while performing an analysis

Examples

## 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

Description

Get meta types from standard_footnotes.yaml

Usage

get_meta_type(path_to_footnotes_yaml)

Arguments

path_to_footnotes_yaml

The file path to the standard_footnotes.yaml file.

Value

A list of meta_type to be called while performing an analysis

Examples

## 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)

get_venv_uv_paths

Description

get_venv_uv_paths

Usage

get_venv_uv_paths()

Value

list of paths to uv and venv directory for calling py scripts

Examples

## Not run: 
get_venv_uv_paths()

## End(Not run)

Wrapper around the ggplot2 ggsave function. Saves a ggplot (or other grid object) and captures analysis relevant metadata in a .json file

Description

Extension to the ggsave() function that allows capturing object metadata as a separate .json file.

Usage

ggsave_with_metadata(
  filename,
  plot = ggplot2::last_plot(),
  meta_type = "NA",
  meta_equations = NULL,
  meta_notes = NULL,
  meta_abbrevs = NULL,
  ...
)

Arguments

filename

The filename for the plot to save to.

plot

The plot object to save. Default is the last displayed plot (ggplot2::last_plot()).

meta_type

A string to specify the type of object. Default is "NA".

meta_equations

A string or vector of strings representing equations to include in the metadata. Default is NULL.

meta_notes

A string or vector of strings representing notes to include in the metadata. Default is NULL.

meta_abbrevs

A string or vector of strings representing abbreviations to include in the metadata. Default is NULL.

...

Additional arguments passed to the ggplot2::ggsave() function.

Examples

## 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)

Initializes python virtual environment

Description

Initializes python virtual environment

Usage

initialize_python(continue = NULL)

Arguments

continue

Optional argument to bypass asking user for confirmation to install python deps

Value

invisibly the metadata_file path

Examples

## Not run: 
initialize_python()

## End(Not run)

Create report directories within a project

Description

Create report directories within a project

Usage

initialize_report_project(
  project_dir,
  report_dir_name = NULL,
  outputs_dir_name = NULL
)

Arguments

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 NULL. If NULL, report will be used.

outputs_dir_name

The directory name for where artifacts will be saved. Default is NULL. If NULL, OUTPUTS will be used.

Examples

## Not run: 
initialize_report_project(project_dir = tempdir())

## End(Not run)

Helper function that defines document output paths

Description

Helper function that defines document output paths

Usage

make_doc_dirs(docx_in)

Arguments

docx_in

The file path to the input .docx file.

Value

A list of document paths

Examples

## 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

Description

Previews a single metadata file for an object

Usage

preview_metadata(file_name)

Arguments

file_name

The file path of the file whose metadata you want to preview.

Value

A single row data frame consisting of metadata type and footnotes for the object supplied

Examples

## 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

Description

Preview all metadata .json files in a directory

Usage

preview_metadata_files(file_dir)

Arguments

file_dir

The file path to a directory containing metadata .json files.

Value

A data frame of metadata footnotes and meta type

Examples

## Not run: 
figures_path <- here::here("OUTPUTS", "figures")
preview_metadata_file(figures_path)

## End(Not run)

Removes Tables, Figures, and Footnotes from a Word file

Description

Reads in a .docx file and returns a new version with tables, figures, and footnotes removed from the document.

Usage

remove_tables_figures_footnotes(docx_in, docx_out, config_yaml = NULL)

Arguments

docx_in

The file path to the input .docx file.

docx_out

The file path to the output .docx file to save to.

config_yaml

The file path to the config.yaml. Default is NULL, a default config.yaml bundled with the reportifyr package is used.

Examples

## 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)

reportifyr: An R package to aid in the drafting of reports.

Description

This pacakge aims to ease table, figure, and footnote insertion and formatting into reports.

reportifyr setup functions

  • 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.

Analysis output saving functions

metadata interaction functions

  • 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.

Document interaction functions

Report building function

Utility functions

Author(s)

Maintainer: Jacob Dumbleton [email protected]

Authors:

Other contributors:

See Also

Useful links:


Wrapper around the saveRDS function. Saves an object as .RDS and .RTF and captures analysis relevant metadata in a .json file

Description

Extension to the saveRDS() function that allows capturing object metadata as a separate .json file.

Usage

save_rds_with_metadata(
  object,
  file = "",
  config_yaml = NULL,
  meta_type = "NA",
  meta_equations = NULL,
  meta_notes = NULL,
  meta_abbrevs = NULL,
  table1_format = FALSE,
  ...
)

Arguments

object

The R object to serialize.

file

The connection or name of the file where the R object is saved.

config_yaml

The file path to the config.yaml. Default is NULL. If NULL, a default value of TRUE for save_rtf() is used.

meta_type

A string to specify the type of object. Default is "NA".

meta_equations

A string or vector of strings representing equations to include in the metadata. Default is NULL.

meta_notes

A string or vector of strings representing notes to include in the metadata. Default is NULL.

meta_abbrevs

A string or vector of strings representing abbreviations to include in the metadata. Default is NULL.

table1_format

A boolean indicating whether to apply table1-style formatting. Default is FALSE.

...

Additional arguments passed to the saveRDS() function.

Examples

## 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)

Synchronizes report project with config and python dependencies set through options. Uses .report_dir_name_init.json to track differences.

Description

Synchronizes report project with config and python dependencies set through options. Uses .report_dir_name_init.json to track differences.

Usage

sync_report_project(project_dir, report_dir_name = NULL)

Arguments

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 NULL. If NULL, report will be used.

Examples

## Not run: 
sync_report_project(here::here())

## End(Not run)

Updates the logging level for functions. Default is set to WARN

Description

Updates the logging level for functions. Default is set to WARN

Usage

toggle_logger(quiet = FALSE)

Arguments

quiet

suppresses messaging about log level.

Examples

## Not run: 
Sys.setenv("RPFY_VERBOSE" = "DEBUG")
toggle_logger()

## End(Not run)

Updates an object's footnote metadata - equations, notes, or abbreviations

Description

Updates an object's footnote metadata - equations, notes, or abbreviations

Usage

update_object_footnotes(
  file_path,
  overwrite = FALSE,
  meta_equations = NULL,
  meta_notes = NULL,
  meta_abbrevs = NULL
)

Arguments

file_path

The file path to the object or its metadata file.

overwrite

A boolean indicating whether to overwrite existing metadata entries. Default is FALSE (appends to existing entries).

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.

Examples

## 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

Description

Validate alt text of figures/tables against their magic strings in a Microsoft Word file

Usage

validate_alt_text_magic_strings(docx_in, debug = FALSE)

Arguments

docx_in

The file path to the input .docx file.

debug

Debug.

Examples

## Not run: 
validate_alt_text_magic_strings("template.docx")

## End(Not run)

Validate config.yaml file

Description

Validate config.yaml file

Usage

validate_config(path_to_config_yaml)

Arguments

path_to_config_yaml

The file path to the config.yaml.

Value

bool TRUE if config is valid, FALSE otherwise.

Examples

## Not run: 
validate_config(here::here("report/config.yaml"))

## End(Not run)

Validates input Microsoft Word file to ensure proper functionality with reportifyr

Description

Validates input Microsoft Word file to ensure proper functionality with reportifyr

Usage

validate_docx(docx_in, config_yaml)

Arguments

docx_in

The file path to the input .docx file.

config_yaml

The file path to the config.yaml.

Examples

## 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

Description

Validates a file's hash against a stored hash in the associated _metadata.json file

Usage

validate_object(file)

Arguments

file

The connection or name of the file where the R object is saved.

Value

A boolean declaring if the hashes are equal or not

Examples

## 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)

Wrapper around the write.csv function. Saves data as .RDS and .RTF and captures analysis relevant metadata in a .json file

Description

Extension to the write.csv() function that allows capturing object metadata as a separate .json file.

Usage

write_csv_with_metadata(
  object,
  file,
  config_yaml = NULL,
  meta_type = "NA",
  meta_equations = NULL,
  meta_notes = NULL,
  meta_abbrevs = NULL,
  table1_format = FALSE,
  ...
)

Arguments

object

The R object to serialize.

file

The connection or name of the file where the R object is saved.

config_yaml

The file path to the config.yaml. Default is NULL. If NULL, a default value of TRUE for save_rtf() is used.

meta_type

A string to specify the type of object. Default is "NA".

meta_equations

A string or vector of strings representing equations to include in the metadata. Default is NULL.

meta_notes

A string or vector of strings representing notes to include in the metadata. Default is NULL.

meta_abbrevs

A string or vector of strings representing abbreviations to include in the metadata. Default is NULL.

table1_format

A boolean indicating whether to apply table1-style formatting. Default is FALSE.

...

Additional arguments passed to the utils::write.csv() function.

Examples

## 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

Description

Writes an object's metadata .json file

Usage

write_object_metadata(
  object_file,
  meta_type = NULL,
  meta_equations = NULL,
  meta_notes = NULL,
  meta_abbrevs = NULL,
  table1_format = FALSE
)

Arguments

object_file

The file path of the object to write metadata for.

meta_type

A string to specify the type of object. Default is "NA".

meta_equations

A string or vector of strings representing equations to include in the metadata. Default is NULL.

meta_notes

A string or vector of strings representing notes to include in the metadata. Default is NULL.

meta_abbrevs

A string or vector of strings representing abbreviations to include in the metadata. Default is NULL.

table1_format

A boolean indicating whether table1 formatting is used for add_tables(). Default is FALSE.

Examples

## 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)