Skip to contents

Data from the IEA have years in columns, but the tidy data format requires one row for each datum. This function uses tidyr::pivot_longer() to make an IEA data frame tidy.

Usage

tidy_iea_df(
  .iea_df,
  col_names = IEATools::iea_cols,
  year = col_names$year,
  e_dot = col_names$e_dot,
  method = col_names$method,
  last_stage = col_names$last_stage,
  country = col_names$country,
  ledger_side = col_names$ledger_side,
  flow_aggregation_point = col_names$flow_aggregation_point,
  energy_type = col_names$energy_type,
  unit = col_names$unit,
  flow = col_names$flow,
  product = col_names$product,
  remove_zeroes = TRUE
)

Arguments

.iea_df

A IEA data frame whose columns have been renamed by rename_iea_df_cols().

col_names

A list of column names in IEA data frames. Default is IEATools::iea_cols.

year

The name of the year column created in .iea_df by this function. Default is col_names$year.

e_dot

The name of the energy/exergy value column created in .iea_df by this function. Default is col_names$e_dot.

method

The name of the method column created in .iea_df by this function. Default is col_names$method.

last_stage

The name of the last stage column created in .iea_df by this function. Default is col_names$last_stage.

country

The name of the country column in .iea_df. Default is col_names$country.

ledger_side

The name of the ledger side in .iea_df. Default is col_names$ledger_side.

flow_aggregation_point

The name of the flow aggregation point column in .iea_df. Default is col_names$flow_aggregation_point.

energy_type

The name of the energy type column in .iea_df. Default is col_names$energy_type.

unit

The name of the unit column in .iea_df. Default is col_names$unit.

flow

The name of the flow column in .iea_df. Default is col_names$flow.

product

The name of the product column in .iea_df. Default is col_names$product.

remove_zeroes

A logical indicating whether data points with the value 0 are to be removed from the output. Default is TRUE.

Value

A tidy version of .iea_df containing new columns year and e_dot and, optionally, 0 values removed.

Details

Default argument values assume that rename_iea_df_cols() has been called on .iea_df.

Examples

sample_iea_data_path() %>% 
  iea_df() %>%
  rename_iea_df_cols() %>% 
  remove_agg_memo_flows() %>% 
  use_iso_countries() %>% 
  augment_iea_df() %>% 
  tidy_iea_df()
#> # A tibble: 403 × 11
#>    Country Method Energy.type Last.stage  Year Ledger.side
#>    <chr>   <chr>  <chr>       <chr>      <dbl> <chr>      
#>  1 GHA     PCM    E           Final       1971 Supply     
#>  2 GHA     PCM    E           Final       2000 Supply     
#>  3 GHA     PCM    E           Final       1971 Supply     
#>  4 GHA     PCM    E           Final       2000 Supply     
#>  5 GHA     PCM    E           Final       1971 Supply     
#>  6 GHA     PCM    E           Final       2000 Supply     
#>  7 GHA     PCM    E           Final       2000 Supply     
#>  8 GHA     PCM    E           Final       2000 Supply     
#>  9 GHA     PCM    E           Final       1971 Supply     
#> 10 GHA     PCM    E           Final       2000 Supply     
#> # ℹ 393 more rows
#> # ℹ 5 more variables: Flow.aggregation.point <chr>, Flow <chr>, Product <chr>,
#> #   Unit <chr>, E.dot <dbl>