Trace a per-crop nitrogen category through the FABIO footprint framework and
return the consumption-side embodied nitrogen split into domestic and traded
flows. The category selects which nitrogen mass is carried as the footprint
intensity (see build_n_exceedance_extension()): "exceedance" (default),
"within_boundary", or "production" (the crop's harvest removal:
harvested product plus used residue plus grazed forage).
The pipeline is build_n_exceedance_extension() to assemble the extension,
build_footprint() to trace it through the multi-regional input-output model,
then a domestic-versus-traded relabelling of the tidy flows: a flow is
"Domestic consumption" when the nitrogen is emitted and consumed in the same
area (origin_area == target_area) and "Traded" otherwise. Two outputs are
returned, mirroring Global's FP_all_N and FP_food_all_N: fp_all is the
embodied nitrogen across all final-demand categories, fp_food is the subset
consumed as food (target_fd == "food").
Signed crop attributions are traced as separate positive and negative linear
extensions and recombined. Explicit undefined-attribution residuals are
rejected by build_n_exceedance_extension() before tracing.
Arguments
- exceedance
A
build_n_boundary_exceedance()country-resolution output passed straight tobuild_n_exceedance_extension(). Not needed whenexample = TRUE.- io
Optional pre-built
build_io_model()result reused across extensions. WhenNULL(default),build_footprint()builds it foryearsfrom the package inputs (the real-data path, an integration wiring step).- category
Which per-crop nitrogen mass to trace:
"exceedance"(default),"within_boundary", or"production". Validated withrlang::arg_match().- years
Years to trace. Defaults to the years present in the extension; ignored when
iois supplied.- data
Optional named list of injected inputs.
data$fp_flowssupplies pre-traced tidy footprint flows (as frombuild_footprint()) directly, bypassing the model build, for testing the split logic in isolation.data$origin_classesmay supply producer classifications keyed byyear,area_code,item_cbs_code(for exampleclassify_sjos_n()output).- example
If
TRUE, return a small hardcoded fixture instead of running the pipeline. Defaults toFALSE.
Value
A named list with two tibbles:
fp_all: embodied nitrogen byyear, producerorigin_area/origin_item, consumertarget_area/target_item,target_fd,origin("Domestic consumption"or"Traded"),item_cbs_code(an alias oftarget_item) andimpact_u(tonnes N), stamped with the tracedcategoryand optional producer classes.fp_food:fp_allrestricted to food consumption (target_fd == "food").
Examples
build_sjos_n_footprint(example = TRUE)
#> $fp_all
#> # A tibble: 5 × 10
#> year origin_area origin_item target_area target_item target_fd origin
#> <int> <int> <int> <int> <int> <chr> <chr>
#> 1 2000 1 10 1 10 food Domestic con…
#> 2 2000 1 20 1 20 other_uses Domestic con…
#> 3 2000 1 10 2 10 food Traded
#> 4 2000 2 10 2 10 food Domestic con…
#> 5 2000 2 20 2 20 food Domestic con…
#> # ℹ 3 more variables: impact_u <dbl>, item_cbs_code <int>, category <chr>
#>
#> $fp_food
#> # A tibble: 4 × 10
#> year origin_area origin_item target_area target_item target_fd origin
#> <int> <int> <int> <int> <int> <chr> <chr>
#> 1 2000 1 10 1 10 food Domestic cons…
#> 2 2000 1 10 2 10 food Traded
#> 3 2000 2 10 2 10 food Domestic cons…
#> 4 2000 2 20 2 20 food Domestic cons…
#> # ℹ 3 more variables: impact_u <dbl>, item_cbs_code <int>, category <chr>
#>
