【发布时间】:2014-03-31 07:59:12
【问题描述】:
我经常使用 windows 将文件路径复制并粘贴到 R 脚本中,结果如下:
file = 'C:\this\is\a\test.tif'
但是,这会导致错误,我必须手动将路径分隔符从 \ 切换到 /
>file = 'C:\this\is\a\test.tif'
Error: '\i' is an unrecognized escape in character string starting "'C:\this\i"
如果我使用的是 Python,我只需使用以下内容来正确格式化路径:
file = r'C:\this\is\a\test.tif'
是否有类似于 Python 的原始字符串 r'' 方法的 R 方法来快速格式化路径?
【问题讨论】:
-
不幸的是 R 不支持原始字符串。解决方法可能是
scan: stackoverflow.com/a/11812540 -
您可以使用 RStudio 的 sn-p 功能来减少粘贴 Windows 路径的痛苦。见stackoverflow.com/a/39989341/3827849
-
@BlueMagister From R 4.0.0 支持原始字符串。见Escaping backslash () in string or paths in R
标签: python r path formatting