1

I need to ">" with "\". Example : "a>b" should be changed to "a\b"

I have tried gsub

> test <- "a>b"
> gsub(">","\\",test, fixed = TRUE)
[1] "a\\b"

I have tried StringR str_replace

> library(stringr)
> str_replace(test,">","\\")
[1] "ab"

I have tried Stringi str_replace_all_fixed

> library(stringi)
> stri_replace_all_fixed(test,">","\\")
[1] "a\\b"

How do I escape \ in replacement. I guess when you give \, it is expecting \1, \2 etc for captured groups. How to avoid this

saiki4116
  • 323
  • 1
  • 4
  • 14

0 Answers0