Skip to contents

Flow and Product columns of IEA data frames may have been "specified" with one of the functions of specify_all(). The specifying makes it difficult to sort the columns in IEA order (with sort_iea_df()), as the Flow and Product columns now contain non-IEA flows and products. To enable sorting, this function de-specifies a column in .df.

Usage

despecify_col(
  .df,
  col,
  despecified_col,
  notations = list(RCLabels::of_notation, RCLabels::from_notation),
  production = IEATools::tpes_flows$production,
  resources = IEATools::tpes_flows$resources
)

Arguments

.df

The data frame in which col exists.

col

The string name of the column in .df to be de-specified.

despecified_col

The string name of the column in the output data frame to contain the de-specified version of col.

notations

The notations used for row and column names. See matsbyname::notation_vec(). Default is list(RCLabels::of_notation, RCLabels::from_notation), because both RCLabels::of_notation and RCLabels::from_notation can be used in the Flow column of an IEA data frame.

production, resources

See IEATools::tpes_flows.

Value

A de-specified version of .df and the result placed in the despecified_col column.

Details

De-specifying includes the following changes: * Any "Resource" flows are replaced by "Production". E.g., "Resources [of Coal]" becomes "Production". * All parenthetical decorations are removed. E.g., "Other bituminous coal [of Coal mines]" becomes "Other bituminous coal".

Identification of parenthetical notation delimiters is determined by a notation object.

Examples

library(dplyr)
load_tidy_iea_df() %>% 
  specify_all() %>% 
  despecify_col(col = "Flow", despecified_col = "clean_Flow") %>% 
  select(Flow, Product, Edot, clean_Flow) %>% 
  filter(endsWith(Flow, RCLabels::bracket_notation[["suff_end"]]))
#> # A tibble: 102 × 4
#>    Flow                                    Product               Edot clean_Flow
#>    <chr>                                   <chr>                <dbl> <chr>     
#>  1 Resources [of Hydro]                    Hydro [from Resou…  10472. Production
#>  2 Resources [of Primary solid biofuels]   Primary solid bio…  87400. Production
#>  3 Manufacture [of Hydro]                  Hydro               10472. Manufactu…
#>  4 Manufacture [of Hydro]                  Hydro [from Resou… -10472. Manufactu…
#>  5 Manufacture [of Primary solid biofuels] Primary solid bio…  87400. Manufactu…
#>  6 Manufacture [of Primary solid biofuels] Primary solid bio… -87400. Manufactu…
#>  7 Resources [of Hydro]                    Hydro [from Resou…  23792. Production
#>  8 Resources [of Primary solid biofuels]   Primary solid bio… 162909. Production
#>  9 Manufacture [of Hydro]                  Hydro               23792. Manufactu…
#> 10 Manufacture [of Hydro]                  Hydro [from Resou… -23792. Manufactu…
#> # ℹ 92 more rows