Skip to contents

Chains the SUBE import → domestic filter → matrix construction → compute step into a single call, returning a structured result with unified diagnostics. The FIGARO source routes through read_figaro(); WIOD-style CSVs/workbooks route through import_suts().

Usage

run_sube_pipeline(
  path,
  cpa_map,
  ind_map,
  inputs,
  source = c("wiod", "figaro"),
  domestic_only = TRUE,
  estimate = FALSE,
  ...
)

Arguments

path

Single character path to a SUT file or directory (WIOD: workbook/CSV or dir; FIGARO: directory containing supply+use flatfiles).

cpa_map, ind_map

Correspondence tables; see build_matrices().

inputs

Industry-level inputs with columns YEAR, REP, an industry identifier, and at least GO.

source

One of "wiod" or "figaro". Selects the importer. No auto-detect (D-8.2).

domestic_only

If TRUE (default), runs extract_domestic_block() on the imported SUTs before building matrices.

estimate

If TRUE and build_matrices(..., inputs = inputs) produces non-empty $model_data, also runs estimate_elasticities() and attaches the result to $models. Default FALSE (D-8.4).

...

Importer-specific arguments (e.g. sheets, recursive for WIOD; year, final_demand_vars for FIGARO) and compute-specific arguments (e.g. metrics, diagonal_adjustment, zero_replacement) forwarded to compute_sube().

Value

An object of class c("sube_pipeline_result", "list") with elements $results (the sube_results object), $models (a sube_models object from estimate_elasticities() or NULL), $diagnostics (a unified diagnostics data.table; see Details), and $call (provenance metadata).

Details

The diagnostics table has columns country (character; NA for pipeline-level aggregates), year (integer; NA for pipeline-level aggregates), stage (import, build, compute, or pipeline), status (ok, singular_supply, singular_go, singular_leontief, skipped_alignment, coerced_na, inputs_misaligned, or error), message (human-readable reason), and n_rows (optional row count, populated for coerced_na aggregates). If any row has status != "ok" a single warning() summarising counts is emitted at the end of the call.

Examples

sut_path <- system.file("extdata", "sample", "sut_data.csv", package = "sube")
result <- run_sube_pipeline(
  path    = sut_path,
  cpa_map = sube_example_data("cpa_map"),
  ind_map = sube_example_data("ind_map"),
  inputs  = sube_example_data("inputs"),
  source  = "wiod"
)
#> Warning: Pipeline completed with issues: 1 inputs_misaligned. See result$diagnostics for details.
result$results$summary
#>     YEAR COUNTRY CPAagg       GO        VA       EMP       CO2    FD      GOe
#>    <int>  <char> <char>    <num>     <num>     <num>     <num> <num>    <num>
#> 1:  2020     AAA    P01 1.625000 0.5416667 0.3993056 0.2569444     6 3.192982
#> 2:  2020     AAA    P02 1.428571 0.4761905 0.3214286 0.1666667     5 2.339181
#>         VAe     EMPe     CO2e
#>       <num>    <num>    <num>
#> 1: 3.192982 3.324157 3.639344
#> 2: 2.339181 2.229869 1.967213
result$diagnostics
#>    country  year   stage            status
#>     <char> <int>  <char>            <char>
#> 1:     AAA  2020   build inputs_misaligned
#> 2:     AAA  2020 compute                ok
#>                                                                                            message
#>                                                                                             <char>
#> 1: Country-year AAA_2020 present in both SUT and inputs but absent from build_matrices model_data.
#> 2:                                                                                              ok
#>    n_rows
#>     <int>
#> 1:     NA
#> 2:     NA

if (FALSE) { # \dontrun{
# FIGARO branch needs a directory with real or synthetic FIGARO flatfiles:
figaro_dir <- system.file("extdata", "figaro-sample", package = "sube")
run_sube_pipeline(
  path    = figaro_dir,
  cpa_map = my_cpa_map,     # user-supplied
  ind_map = my_ind_map,
  inputs  = my_inputs,
  source  = "figaro",
  year    = 2023L
)
} # }