mgsub: Multiple gsub Replacement

Description Usage Arguments Value Note Examples

Description

Multiple gsub replacement: Replaces the need for multiple, consecutive gsub functions. If you have more than once replacement rule then this convenience function is appropriate to use.

Usage

1
mgsub(x, replace_list)

Arguments

x

a character vector where matches are sought, or an object which can be coerced by as.character to a character vector. Long vectors are supported.

replace_list

A list of at least length one where each element is of length 2. Each two element vector has the 'old' pattern and the 'new' replacement which are passed to gsub via Reduce.

Value

a character vector of the same length and with the same attributes as x (after possible coercion to character). Elements of character vectors x which are not substituted will be returned unchanged. See ?gsub for further details.

Note

Code idea taken from: http://stackoverflow.com/questions/15253954/replace-multiple-arguments-with-gsub

Examples

1
2
3
ex_string = 'Here are the two dates: @startdate, @enddate'
ex_list = list(c('@startdate', '10/1/2010'), c('@enddate', '9/30/2012'))
mgsub(x = ex_string, replace_list = ex_list)

equastat/Emisc documentation built on May 16, 2019, 8:24 a.m.