I have a string like this:
vect <- c("Thin lines are not great, I am in !!! AND You shouldn't be late OR you loose")
I want to replace, "in" to %in%", "AND" to "&", "OR" to "|".
I know this can be done using gsub like below:
gsub("\\bin\\b","%in%", vect),
but I need three different lines for each of the replacement, hence I choose to use gsubfn
.
so I tried,
gsubfn("\\bin\\b|\\bAND\\b|\\bOR\\b", list("in"="%in%", "AND"= "&", "OR"="|"), vect)
but It returns a string with nothing changed, for some reason \\b
is not working for the string. However, \\b
does work great with gsub
and I am able to replace all the three strings in by piping together using gsub
.
My question is, why \\b
is not working inside gsubfn
. what I am missing inside my regex?
Please help.
Output should be:
"Thin lines are not great, I am %in% !!! & You shouldn't be late | you loose"
This works:
gsubfn("\\w+", list("in"="%in%", "AND"= "&", "OR"="|"), vect)