无论输入字符串中出现多少次,我都希望用'/'替换'\'。
我已阅读以下内容:Replace "\" with "/" in r
Efficiently convert backslash to forward slash in R
但是它们两个都提供了解决方案,即通过剪贴板粘贴或scan()读取directory_path。
我想将目录路径作为变量。
示例代码:
directory_path = 'D:\demo\app'
gsub( '\', '/', directory_path )
但是它给出了错误。
> directory_path = 'D:\demo\app'
Error: '\d' is an unrecognized escape in character string starting "'D:\d"
答案 0 :(得分:2)
像这样逃避它们:
test <- c("D:\\demo\\app")
然后:
gsub("\\\\", "/", test)