mgsub_censor {mgsub}R Documentation

Safe, multiple censoring of text strings

Description

mgsub_censor - A safe, simultaneous, multiple global string censoring (replace matches with a censoring character like '*')

Usage

mgsub_censor(string, pattern, censor = "*", split = any(nchar(censor) >
  1), seed = NULL, ...)

Arguments

string

a character vector to censor

pattern

regular expressions used to identify where to censor

censor

character to use in censoring - see details

split

if a multicharacter censor pattern is provided, should it be split to preserve original string length

seed

optional parameter to fix sampling of multicharacter censors

...

arguments to pass to regexpr / sub

Details

When censor is provided as a >1 length vector or as a multicharacter string with split = TRUE, it will be sampled to return random censoring patterns. This can be helpful if you want to create cartoonish swear censoring. If needed, the randomization can be controlled with the seed argument.

Value

Censored string.

Examples

mgsub_censor("Flowers for a friend", pattern=c("low"), censor="*")

[Package mgsub version 1.7.3 Index]