aggregate_regions: Aggregates IEA regions based on a user-defined aggregation...

View source: R/aggregates.R

aggregate_regionsR Documentation

Aggregates IEA regions based on a user-defined aggregation table.

Description

Takes as input a tidy dataframe, an aggregation table routing IEA regions to destination regions (as a data frame), and aggregates flows per regions following the user-defined aggregation table. The boolean argument 'net_tradeā€œ enables to perform the aggregation by keeping only net imports and/or net exports or by keeping gross imports and exports.

Usage

aggregate_regions(
  .tidy_iea_df,
  aggregation_table = read_aggregation_region_table(),
  net_trade = FALSE,
  destination_regions = "Destination_regions",
  iea_regions = "IEA_regions",
  imports = IEATools::interface_industries$imports,
  exports = IEATools::interface_industries$exports,
  country = IEATools::iea_cols$country,
  e_dot = IEATools::iea_cols$e_dot,
  flow = IEATools::iea_cols$flow,
  year = IEATools::iea_cols$year,
  ledger_side = IEATools::iea_cols$ledger_side,
  flow_aggregation_point = IEATools::iea_cols$flow_aggregation_point,
  product = IEATools::iea_cols$product,
  etwmb = IEATools::tpes_flows$exports_to_world_marine_bunkers,
  etwab = IEATools::tpes_flows$exports_to_world_aviation_bunkers,
  .net_imports = "Net_Imports"
)

Arguments

.tidy_iea_df

The .tidy_iea_df data frame that needs to be aggregated by regions. The .tidy_iea_df is likely to have been obtained with the load_tidy_iea_df() function.

aggregation_table

An aggregation table that routes the IEA regions (iea_regions column) to destination regions (destination_regions column). The aggregation table can be built manually or loaded from an Excel file with the read_aggregation_region_table() function. Default is the 2019 IEA to Exiobase aggregation table, as provided by the read_aggregation_region_table() function.

net_trade

The boolean that defines whether imports and exports by aggregation region should be converted into net imports / exports or not. Default is FALSE.

destination_regions

The name of the destination_regions in the aggregation_table data frame. Default is "Destination_regions".

iea_regions

The name of the iea_regions in the aggregation_table data frame. Default is "IEA_regions".

imports

The name of the imports flow in the .tidy_iea_df. Default is IEATools::interface_industries$imports.

exports

The name of the exports flow in the .tidy_iea_df. Default is IEATools::interface_industries$exports.

country

The name of the country column in the .tidy_iea_df. Default is IEATools::iea_cols$country.

e_dot

The name of the e_dot column in the .tidy_iea_df. Default is IEATools::iea_cols$e_dot.

flow

The name of the flow column in the .tidy_iea_df. Default is IEATools::iea_cols$flow.

year

The name of the year column in the .tidy_iea_df. Default is IEATools::iea_cols$year.

ledger_side

The name of the ledger_side column in the .tidy_iea_df. Default is IEATools::iea_cols$ledger_side.

flow_aggregation_point

The name of the flow_aggregation_point column in the .tidy_iea_df. Default is IEATools::iea_cols$flow_aggregation_point.

product

The name of the product column in the .tidy_iea_df. Default is IEATools::iea_cols$product.

etwmb, etwab

The string identifiers for exports to world marine and aviation bunkers. These exports are out of a country and into the "WMBK" or "WABK" countries. Defaults are IEATools::tpes_flows$exports_to_world_marine_bunkers and IEATools::tpes_flows$exports_to_world_aviation_bunkers.

.net_imports

The name of the .net_import variable, that is only used internally to the function. Not returned. Default is "Net_Imports". It is suggested that this parameter is only used in the particular case that there is a column or a flow named "Net_Imports" in the .tidy_iea_df input data frame.

Value

A .tidy_iea_df that contains the data of the input .tidy_iea_df aggregated by regions as specified in the user-defined country aggregation table provided.

Examples

# Performs the regional aggregation using the default IEA to Exiobase mapping 
# for IEA data 2019, using the example `.tidy_iea_df` 
# returned by the `load_tidy_iea_df()` function when run without argument.
aggregate_regions(.tidy_iea_df = load_tidy_iea_df())
# Performs the regional aggregation using the default IEA to Exiobase mapping 
# for IEA data 2020, using the example `.tidy_iea_df` 
# returned by the `load_tidy_iea_df()` function when run without argument.
aggregate_regions(.tidy_iea_df = load_tidy_iea_df(), 
                  aggregation_table = read_aggregation_region_table(
                    default_aggregation_region_table_path(2020)))

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