1

Similar to R - delete last two characters in string if they match criteria except I'm trying to get rid of the special character '+' as well. I also attached a picture of my output.

When I attempt to use the escape command of '+', I get an error message saying

Error: '\+' is an unrecognized escape in character string starting ""\\s\+"

Image of output with '+ off' showing

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
SamMusch
  • 11
  • 1
  • 2

1 Answers1

2

As you noticed, + is a metacharacter in regex so it needs to be escaped. \+ escapes that character, but \, itself, is a special character in R character strings so it, too, needs to be escaped. This is an R requirement, not a regex requirement.

This means that, instead of '\+', you need to write '\\+'.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214