filesstrings (version 2.0.1)

singleize: Remove back-to-back duplicates of a pattern in a string.

Description

If a string contains a given pattern duplicated back-to-back a number of times, remove that duplication, leaving the pattern appearing once in that position (works if the pattern is duplicated in different parts of a string, removing all instances of duplication). This is vectorized over string and pattern.

Usage

singleize(string, pattern)

Arguments

string

A character vector. The string(s) to be purged of duplicates.

pattern

A character vector. Regular expression(s) of the pattern(s) that we wish not to be duplicated.

Value

The string with the duplicates fixed.

Examples

Run this code
# NOT RUN {
singleize("abc//def", "/")
singleize("abababcabab", "ab")
singleize(c("abab", "cdcd"), "cd")
singleize(c("abab", "cdcd"), c("ab", "cd"))
# }

Run the code above in your browser using DataCamp Workspace