R 中文件路径的原始文本字符串 [英] Raw text strings for file paths in R
问题描述
在 R 中指定文件路径字符串时是否可以使用前缀来忽略转义字符?
Is it possible to use a prefix when specifying a filepath string in R to ignore escape characters?
例如如果我想在使用windows时读入文件example.csv
,我需要手动将\
更改为/
或<代码>\\代码>.例如,
For example if I want to read in the file example.csv
when using windows, I need to manually change \
to /
or \\
. For example,
'E:\DATA\example.csv'
变成
'E:/DATA/example.csv'
data <- read.csv('E:/DATA/example.csv')
在 python
中,我可以使用 r
为字符串添加前缀以避免这样做(例如 r'E:\DATA\example.csv'
).R
中是否有类似的命令,或者我可以用来避免出现此问题的方法.(我在 windows、mac 和 linux 之间移动 - 这显然只是 windows 操作系统上的一个问题).
In python
I can prefix my string using r
to avoid doing this (e.g. r'E:\DATA\example.csv'
). Is there a similar command in R
, or an approach that I can use to avoid having this problem. (I move between windows, mac and linux - this is just a problem on the windows OS obviously).
推荐答案
现在可以使用 R 版本 4.0.0.请参阅?Quotes
了解更多.
It is now possible with R version 4.0.0. See ?Quotes
for more.
示例
r"(c:\Program files\R)"
## "c:\\Program files\\R"
这篇关于R 中文件路径的原始文本字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!