Remove specification strings from a column
despecify_col.RdFlow 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
colexists.- col
The string name of the column in
.dfto 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 islist(RCLabels::of_notation, RCLabels::from_notation), because bothRCLabels::of_notationandRCLabels::from_notationcan be used in theFlowcolumn of an IEA data frame.- production, resources
See
IEATools::tpes_flows.
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