remove_suffix_specifications: Remove specification suffixes from a column

View source: R/specify.R

remove_suffix_specificationsR Documentation

Remove specification suffixes from a column

Description

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 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.

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, E.dot, clean_Flow) %>% 
  filter(endsWith(Flow, RCLabels::bracket_notation[["suff_end"]]))

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