Apply multiple string replacements to a data frame column.
replace_abbreviations.Rd
This function iteratively applies a set of pattern-replacement pairs to the 'expression' column of a data frame. It performs multiple passes to ensure all replacements are applied, even if they depend on previous replacements. Patterns are treated as full words (or preceded by non-word characters and followed by non-word characters or an opening parenthesis) to prevent partial word matches.
Arguments
- file
A data frame that must contain a column named
expression
.- replacements
A data frame with at least two columns:
pattern
(strings to be found) andreplacement
(strings to replace them with).- npass
The number of passes to apply the replacements. Multiple passes are useful if replacements can affect subsequent patterns.