Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: How do I replace \\ with /?

Tags:

regex

r

In R I have a string like

file = "c:\\hello\\nihao"

How do I replace all the \ with /? The ?gsub documentation is really confusing! You should get extra points for pointing to a good R regex resource!!

like image 559
xiaodai Avatar asked Nov 30 '22 00:11

xiaodai


1 Answers

Why not just use the fixed = TRUE argument?

gsub("\\", "/", file, fixed=TRUE)
# [1] "c:/hello/nihao"

Alternatively:

gsub("\\\\", "/", file)
# [1] "c:/hello/nihao"
like image 75
A5C1D2H2I1M1N2O1R2T1 Avatar answered Dec 06 '22 08:12

A5C1D2H2I1M1N2O1R2T1