忽略R字符串中的转义字符(反斜杠)
在SPSS中运行R-plugin时,我收到一个Windows路径字符串作为输入,例如
While running an R-plugin in SPSS, I receive a Windows path string as input e.g.
'C:\Users\mhermans\somefile.csv'
我想在后续的R代码中使用该路径,但是斜杠需要用正斜杠替换,否则将R解释为转义(例如\U不使用十六进制数字错误)。
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但是无法找到可以用foward斜杠替换反斜杠的功能,或者双重转义它们。所有这些功能都假定这些角色被转义。
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:\Users\mhermans')
C:/Users/mhermans
您可以尝试在scan()中使用'allowEscapes'参数
You can try to use the 'allowEscapes' argument in scan()
X=scan(what="character",allowEscapes=F)
C:\Users\mhermans\somefile.csv
print(X)
[1] "C:\\Users\\mhermans\\somefile.csv"