% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/replace_multiple.R
\name{replace_multiple}
\alias{replace_multiple}
\title{Replace character vector values using a correspondence approach}
\usage{
replace_multiple(input_vector, replacements, replace_all = FALSE)
}
\arguments{
\item{input_vector}{Character. Character vector on which replacements take place.}

\item{replacements}{Character. Named character vector defining replacement
correspondences (names = patterns, values = replacements). Names are
treated as literal strings (regex metacharacters such as \code{.},
\code{(}, \code{+} are not interpreted).}

\item{replace_all}{Logical. If \code{TRUE}, \code{stringr::str_replace_all()}
is used instead of \code{stringr::str_replace()}.}
}
\value{
Character vector with replacements applied.
}
\description{
Names of \code{replacements} are matched literally (not as regular
expressions). Elements of \code{input_vector} that match none of the
patterns are returned unchanged.
}
\section{Overlapping patterns}{

When several patterns can match the same element, the first match found
in \code{input_vector} (scanned left to right) is used. When patterns
start at the same position, the one listed first in \code{replacements}
wins, not the longest. Order \code{replacements} accordingly if some
patterns are prefixes of others.
}

\examples{
input <- c("one-one", "two-two-one", "three-three-two")

replace_multiple(input,
                 replacements =
                   c("one" = "1", "two" = "2",
                     "three" = "3"))

replace_multiple(input,
                 replacements =
                   c("one" = "1", "two" = "2",
                     "three" = "3"),
                 replace_all = TRUE)

# Unmatched elements are returned as-is:
replace_multiple(c("one", "unmatched"), c("one" = "1"))

# Regex metacharacters are matched literally:
replace_multiple(c("a.b", "aXb"), c("." = "DOT"))
}
