Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R list.files:正则表达式模式在windows上不工作?_R_Regex - Fatal编程技术网

R list.files:正则表达式模式在windows上不工作?

R list.files:正则表达式模式在windows上不工作?,r,regex,R,Regex,我可以使用文件访问并获取文件路径。选择(): 我正在使用一个项目,所以我不必键入整个路径,但在reportes\u mov之后。为什么我的列表文件在运行后为空 files <- list.files(pattern = 'data_mym\\/mym_total_csv\\/hhhh-2020-[0-9]{2}-[0-9]{2}\\.csv') files的模式参数仅与文件名部分匹配,而与路径不匹配: 路径:完整路径名的字符向量;默认值对应于 到工作目录getwd() 模式:可选的正则

我可以使用
文件访问并获取文件路径。选择()

我正在使用一个项目,所以我不必键入整个路径,但在
reportes\u mov
之后。为什么我的列表文件在运行后为空

files  <- list.files(pattern = 'data_mym\\/mym_total_csv\\/hhhh-2020-[0-9]{2}-[0-9]{2}\\.csv')

files的
模式
参数仅与文件名部分匹配,而与路径不匹配:

路径
:完整路径名的字符向量;默认值对应于 到工作目录getwd()

模式
:可选的正则表达式。只有文件名 匹配将返回正则表达式

如果我理解正确,您还需要参数
full.names=TRUE

如果为TRUE,则在文件名前面加上目录路径以给出 相对文件路径。如果为FALSE,则显示文件名(而不是路径) 返回

试一试


data\u lsd
lsd\u total\u csv
之后,在pattern@Thefourthbird请看我的其他尝试。我明白了,请尝试将
\\.
更改为
\.
请参阅更新1,因为模式只处理文件名,而不是路径+名称的完整字符串。如果这样做会发生什么:文件它看起来不像Windows。您的测试路径不在
D:\america\reportes\u mov
。无需。我们在一个项目中,在Windows中工作时,我们可以在路径中使用正斜杠或使用双反斜杠来转义反斜杠。
files  <- list.files(pattern = 'data_mym\\/mym_total_csv\\/hhhh-2020-[0-9]{2}-[0-9]{2}\\.csv')
files  <- list.files(pattern = 'data_mym\\mym_total_csv\\hhhh-2020-[0-9]{2}-[0-9]{2}\\.csv')
files  <- list.files(path = 'data_lsd/lsd_total_csv', pattern = 'america-2020-[0-9]{2}-[0-9]{2}\\.csv', full.names=TRUE, ignore.case = TRUE)
[1] "data_lsd/lsd_total_csv/america-2020-11-09.csv"
[2] "data_lsd/lsd_total_csv/america-2020-11-10.csv"