0

I've looked at some of the answers to questions about removing a special character such as "\" from text string but they're not resolving the issue I'm having removing all backslashes.

I've tried gsub and stringr's str_replace but neither has worked.

str_remove(urls, "\")

gsub("\","",urls)

Removing or trimming all backslashes in the text string.

js80
  • 385
  • 2
  • 11
  • You need to escape the backslash – akrun Oct 17 '19 at 21:27
  • In R as with many (most?) languages, the backslash is used to escape special characters. In order to include the literal backslash, it must be escaped. This is complicated in R because R only allows some specific special characters to use a single-backslash (e.g., `\n`, `\r`, `\t`), and any other use of the backslash must escape itself explicitly ... and sometimes this means escaping the escaped backslash (frustrating as that might sound). So try `str_remove(urls, '\\\\')` and `gsub("\\\\","",urls)`. – r2evans Oct 17 '19 at 21:30
  • That worked. Thanks very much. – js80 Oct 17 '19 at 22:06

0 Answers0