specify_non_energy_use: Specify Non-energy use when possible

View source: R/initialize.R

specify_non_energy_useR Documentation

Specify Non-energy use when possible

Description

For some countries and years, Non-energy use details are supplied by "Memo:" fields. We use those details if they exist. This function assess the energy balance of replacing "Non-energy use industry/transformation/energy" by "Non-energy use in <>" rows. If there is an imbalance, an attempt is made to adjust the imbalance.

Usage

specify_non_energy_use(
  .iea_df,
  country = IEATools::iea_cols$country,
  year = IEATools::iea_cols$year,
  method = IEATools::iea_cols$method,
  energy_type = IEATools::iea_cols$energy_type,
  unit = IEATools::iea_cols$unit,
  ledger_side = IEATools::iea_cols$ledger_side,
  last_stage = IEATools::iea_cols$last_stage,
  flow_aggregation_point = IEATools::iea_cols$flow_aggregation_point,
  flow = IEATools::iea_cols$flow,
  product = IEATools::iea_cols$product,
  non_energy_use = IEATools::aggregation_flows$non_energy_use,
  non_energy_flows_industry_transformation_energy =
    IEATools::non_energy_flows[["non_energy_use_industry_transformation_energy"]],
  memo_non_energy_use_in_industry_not_elsewhere_specified =
    IEATools::memo_non_energy_flows[["memo_non_energy_use_in_industry_not_elsewhere_specified"]],
  non_energy_use_in_industry_not_elsewhere_specified = sub(pattern = paste0("^", memo),
    replacement = "", memo_non_energy_use_in_industry_not_elsewhere_specified),
  memo = IEATools::memo_aggregation_flow_prefixes$memo,
  memo_non_energy_flows_industry =
    IEATools::memo_non_energy_flows$memo_non_energy_use_in_industry,
  memo_non_energy_use_in = "Memo: Non-energy use in ",
  non_energy_use_in = sub(pattern = paste0("^", memo), replacement = "", x =
    memo_non_energy_use_in),
  total = IEATools::memo_aggregation_product_prefixes$total,
  .values = IEATools::template_cols$.values,
  .values_summarised = paste0(.values, "_summarised"),
  .diff = ".diff",
  tol = 1e-06
)

Arguments

.iea_df

A data frame of IEA data, created by augment_iea_df().

country, year, method, energy_type, unit, ledger_side, last_stage, flow_aggregation_point, flow, product

See IEATools::iea_cols.

non_energy_use

See IEATools::aggregation_flows.

non_energy_flows_industry_transformation_energy

See IEATools::non_energy_flows.

memo_non_energy_use_in_industry_not_elsewhere_specified

See IEATools::memo_non_energy_flows.

non_energy_use_in_industry_not_elsewhere_specified

Same as memo_non_energy_use_in_industry_not_elsewhere_specified without the memo prefix.

memo

A string prefix for memo flows. Default is IEATools::memo_aggregation_flow_prefixes$memo.

memo_non_energy_flows_industry

See IEATools::memo_non_energy_flows.

memo_non_energy_use_in

A prefix for specific Non-energy use flows. Default is "Memo: Non-energy use in ".

non_energy_use_in

Same as memo_non_energy_use_in without the memo prefix.

total

See IEATools::memo_aggregation_product_prefixes.

.values

An internal column name. Default is IEATools::template_cols$.values.

.values_summarised

An internal column name. Default is paste0(.values, "_summarised").

.diff

An internal column name. Default is ".diff".

tol

The tolerance for differences from 0. Default is 1e-6.

Details

Note that energy balance checks are not performed on the incoming .iea_df, but that the specification process itself ensures that the modifications, themselves, are balanced. In other words, specifying Non-energy use flows will not change the energy balance of the incoming .iea_df data frame.

This function does not promise the resulting data frame is internally consistent. Rather, this function should be considered a step along the path to creating a coherent data frame of IEA data. Specifically, this function does not specify aggregation or Memo: flows, so coherence will be achieved again only after remove_agg_memo_flows() is called. Note that load_tidy_iea_df(specify_non_energy_flows = TRUE) correctly calls remove_agg_memo_flows() internally, so using load_tidy_iea_df() is preferred to calling specify_non_energy_use() directly.

Value

.iea_df with specified ⁠Non-energy use⁠s, where possible.

Examples

sample_iea_data_path() %>% 
  iea_df() %>%
  rename_iea_df_cols() %>% 
  clean_iea_whitespace() %>%
  augment_iea_df() %>%
  specify_non_energy_use()

MatthewHeun/IEATools documentation built on Feb. 6, 2024, 3:29 p.m.