【发布时间】:2022-08-17 07:34:02
【问题描述】:
我正在尝试编写一个 r 脚本,该脚本将匹配目录中的文件名并将其与位于 csv 文件中的文件名进行比较。这样我就可以知道已经下载了哪些文件以及需要下载哪些数据。我编写的代码将从目录中读取文件并将它们列为 df 以及读取 csv 文件。但是,我无法更改文件名以提取我想要的字符串以及将文件名与 csv 文件中的名称列匹配。理想情况下,我还希望创建一个新的电子表格,它可以告诉我哪些文件匹配,这样我就知道下载了什么。这就是我到目前为止所拥有的。
# read files from directory and list as df
file_names <-list.files(path=\"peaches/\",
pattern=\"jpg\",
all.files=TRUE,
full.names=TRUE,
recursive=TRUE) %>%
# turn into df
as.data.frame(x = file_names)
# read in xl file
name_data <- read_excel(\"peaches/all_data.xlsx\")
# change the file_name from the string peaches//fruit/1234/12pink.jpg.txt to -> 12pink
# match the file name with the name column in name_data
# create a new spread sheet that pulls the id and row if it has been downloaded [enter image description here][1]
-
我提出了一个解决方案。将来,请发布您的文件结构的reproducible example。或者,更多描述会有所帮助。鉴于问题中缺乏细节,我制作了一组示例文件/结构。