Learn R Programming

bivarhr (version 0.1.5)

read_bma_all: Read and consolidate BMA weight tables

Description

Searches for BMA weight CSV files produced by the Hurdle-NB model, reads them using automatic delimiter detection, and returns a single stacked data frame with normalized column names and a combo identifier.

Usage

read_bma_all(dir_csv, dir_out, stop_if_empty = TRUE, verbose = TRUE)

Value

A data frame with all BMA tables stacked and an added combo_id column (source identifier) and a combo

column (control combo). If nothing is found and stop_if_empty = FALSE, an empty tibble is returned.

Arguments

dir_csv

Character scalar; directory where BMA CSV files are expected (for example "bma_weights_specC_ctrl*.csv").

dir_out

Character scalar; output directory used during the experiment, which may contain BMA files or a fallback RDS object.

stop_if_empty

Logical; if TRUE, an informative error is thrown when no valid BMA tables are found. If FALSE, a warning is issued and an empty tibble is returned.

verbose

Logical; if TRUE, prints diagnostic messages about the search paths, files found, and detected ELPD column.

Details

The function:

  • Looks for CSV files matching the pattern "bma_weights_specC_ctrl*.csv" in dir_csv, and if none are found, searches recursively in dir_out.

  • Reads each candidate file via rc_auto() and keeps only non-empty data frames.

  • If no CSV files are usable, optionally falls back to an RDS file "experimento_mejorado_all.rds" under dir_out and tries to extract BMA tables from allobj$bma.

  • Normalizes column names with normalize_names(), ensures a combo column exists, detects the ELPD column, and sorts rows by decreasing ELPD.