Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

While running an R-plugin in SPSS, I receive a Windows path string as input e.g.

'C:Usersmhermanssomefile.csv'

I would like to use that path in subsequent R code, but then the slashes need to be replaced with forward slashes, otherwise R interprets it as escapes (eg. "U used without hex digits" errors).

I have however not been able to find a function that can replace the backslashes with foward slashes or double escape them. All those functions assume those characters are escaped.

So, is there something along the lines of:

>gsub('\', '/', 'C:Usersmhermans')
C:/Users/mhermans
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
590 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can try to use the 'allowEscapes' argument in scan()

X=scan(what="character",allowEscapes=F)
C:Usersmhermanssomefile.csv

print(X)
[1] "C:\Users\mhermans\somefile.csv"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...