load_tidy_iea_df: Load IEA extended energy balance data into tidy format

View source: R/initialize.R

load_tidy_iea_dfR Documentation

Load IEA extended energy balance data into tidy format

Description

Loads an IEA extended energy balance data file in .csv format from disk and converts to a tidy format. This function bundles several others and relies mostly on default values for arguments:

  1. iea_df(),

  2. rename_iea_df_cols(),

  3. clean_iea_whitespace(),

  4. use_iso_countries(),

  5. augment_iea_df(),

  6. specify_non_energy_use() (optionally),

  7. fix_GHA_industry_electricity() |> fix_GHA_psb() |> fix_COL_electricity_generation() (optionally),

  8. remove_agg_memo_flows(), and

  9. tidy_iea_df().

Usage

load_tidy_iea_df(
  .iea_file = sample_iea_data_path(),
  unit_val = "TJ",
  remove_zeroes = TRUE,
  specify_non_energy_flows = FALSE,
  apply_fixes = FALSE,
  override_df = IEATools::override_iso_codes_df,
  country = IEATools::iea_cols$country,
  pfu_code = IEATools::country_concordance_cols$pfu_code,
  iea_name = IEATools::country_concordance_cols$iea_name
)

Arguments

.iea_file

The path of the file to be loaded. Default loads example data bundled with the package via sample_iea_data_path().

unit_val

The units for this file. Default is "TJ".

remove_zeroes

A logical indicating whether data points with the value 0 are to be removed from the output. This argument is passed to tidy_iea_df(). Default is TRUE.

specify_non_energy_flows

A logical indicating whether "Non-energy use in xxxxx" Flows should be specified by "Memo: Non-energy use in <>" entries in the IEA data. Default is FALSE.

apply_fixes

A logical indicating whether fixes should be applied to IEA data. Default is FALSE.

override_df

A data frame containing columns pfu_code and iea_name that provides 3-letter country codes. See IEATools::use_iso_countries(). Default is IEATools::override_iso_codes_df.

country

The name of the country column in the data frames. See IEATools::iea_cols$country.

pfu_code, iea_name

Names of columns in the override data frame for 3-letter country codes. These arguments are passed to use_iso_countries(). Defaults are taken from IEATools::country_concordance_cols.

Details

Each bundled function is called in turn using default arguments. See examples for two ways to achieve the same result.

Value

A tidy, augmented data frame of IEA extended energy balance data.

Examples

# Check the file first
iea_file_OK(sample_iea_data_path())
# Take a simple approach
simple <- load_tidy_iea_df(specify_non_energy_flows = TRUE)
# Take the complicated approach
complicated <- sample_iea_data_path() |> 
  iea_df() |> 
  rename_iea_df_cols() |> 
  clean_iea_whitespace() |> 
  remove_agg_memo_flows() |>  
  use_iso_countries() |> 
  augment_iea_df() |> 
  specify_non_energy_use() |> 
  tidy_iea_df()
# simple and complicated should be exactly the same
all(simple == complicated)

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