Skip to contents

This function takes a character string or vector and replaces each character in each quoted substrings with a replacement character (by default "_"). When suppress_quoting_char is FALSE (the default), the function preserves the original opening and closing quotes and only censors the inner content. When TRUE, the quotes are also replaced.

Usage

censor_quoted_text(
  text,
  char_for_replacing_each_char = "_",
  suppress_quoting_char = FALSE
)

Arguments

text

A character string containing the text to process.

char_for_replacing_each_char

A single character string to be used for replacing each character in the substring.

suppress_quoting_char

Logical. If TRUE, the quoting characters are replaced as well; if FALSE (default), they are preserved.

Value

A character string with the content inside each quoted substring censored.

Examples

# Censor quoted content and keep the quotes:
text <- c("Example: \"Rat-terrier\" (aka 'Teddy Roosevelt Terrier')"
, "have served into a 'Truffe-terrier company'.")
censor_quoted_text(text, char_for_replacing_each_char = "_", suppress_quoting_char = FALSE)
#>     Example: "Rat-terrier" (aka 'Teddy Roosevelt Terrier') 
#> "Example: \"___________\" (aka '_______________________')" 
#>               have served into a 'Truffe-terrier company'. 
#>             "have served into a '______________________'." 
# Remove quoted content and also remove the quotes:
censor_quoted_text(text, char_for_replacing_each_char = "", suppress_quoting_char = TRUE)
#> Example: "Rat-terrier" (aka 'Teddy Roosevelt Terrier') 
#>                                     "Example:  (aka )" 
#>           have served into a 'Truffe-terrier company'. 
#>                                 "have served into a ."