Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

mgsub

Safe, multiple gsub


Description

mgsub - A safe, simultaneous, multiple global string replacement wrapper that allows access to multiple methods of specifying matches and replacements.

Usage

mgsub(string, pattern, replacement, recycle = FALSE, ...)

Arguments

string

a character vector where replacements are sought

pattern

Character string to be matched in the given character vector

replacement

Character string equal in length to pattern or of length one which are a replacement for matched pattern.

recycle

logical. should replacement be recycled if lengths differ?

...

arguments to pass to regexpr / sub

Value

Converted string.

Examples

mgsub("hey, ho", pattern = c("hey", "ho"), replacement = c("ho", "hey"))
mgsub("developer", pattern = c("e", "p"), replacement = c("p", "e"))
mgsub("The chemical Dopaziamine is fake",
      pattern = c("dopa(.*?) ", "fake"),
      replacement = c("mega\\1 ", "real"),
      ignore.case = TRUE)

mgsub

Safe, Multiple, Simultaneous String Substitution

v1.7.2
MIT + file LICENSE
Authors
Mark Ewing [aut, cre]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.