despecify_col: Remove specification strings from a column

View source: R/specify.R

despecify_colR Documentation

Remove specification strings from a column

Description

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.

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.

Value

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

Examples

library(dplyr)
load_tidy_iea_df() %>% 
  specify_all() %>% 
  despecify_col(col = "Flow", despecified_col = "clean_Flow") %>% 
  select(Flow, Product, E.dot, clean_Flow) %>% 
  filter(endsWith(Flow, RCLabels::bracket_notation[["suff_end"]]))

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