Remove specification suffixes from a column
remove_suffix_specifications.Rd
Flow
and Product
columns of IEA data frames may have been "specified"
to contain a suffix of the form " [of Natural gas\"], for example.
This function strips away the suffix.
Identification of parenthetical notation delimiters is determined by the notations
argument.
Usage
remove_suffix_specifications(
.df,
col,
unsuffixed_col,
notations = list(RCLabels::of_notation, RCLabels::from_notation)
)
Arguments
- .df
The data frame in which
col
exists.- col
The string name of the column in
.df
to be de-specified.- unsuffixed_col
The string name of the column in the output data frame to contain the un-suffixed 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_notation
andRCLabels::from_notation
can be used in theFlow
column of an IEA data frame.
Value
A version of .df
with suffixes removed from the col
column and the result placed in the despecified_col
column.
Examples
library(dplyr)
load_tidy_iea_df() %>%
specify_all() %>%
remove_suffix_specifications(col = "Flow", unsuffixed_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. Resources
#> 2 Resources [of Primary solid biofuels] Primary solid bio… 87400. Resources
#> 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. Resources
#> 8 Resources [of Primary solid biofuels] Primary solid bio… 162909. Resources
#> 9 Manufacture [of Hydro] Hydro 23792. Manufactu…
#> 10 Manufacture [of Hydro] Hydro [from Resou… -23792. Manufactu…
#> # ℹ 92 more rows