尝试将多个Excel文件读取到数据框架中时会出现错误
通常,当阅读大约100个左右的.xls/.xlsx文件中时,我通常会运行此代码迭代。从来没有问题 - 现在,当尝试执行2000多个文件左右时,我会收到错误错误:
rid1 找不到
- 我读到这可能是因为其中之一是文件是一种较旧的格式 - 但我确认所有Excel文件均为.xls(97-2003工作表)或.xlsx(更现代) - 我一次执行100个左右文件时通常会读取的格式。
我尝试在上面的代码中尝试我通常的迭代,然后在下面的循环中进行较新的迭代,而 rid1 错误都没有运气。会发生什么?
files2 <-
list.files(path = "C:\\path",pattern = "*xls", full.names = TRUE) %>% basename()
data <- tibble(Customer = files2) %>% # create a data frame
mutate(file_contents = map(Customer,
~ read_excel(file.path("C:\\path", .), col_types = "text")) # a new data column and convert to text
)
files <-
list.files(path = "C:\\path", pattern = "*xls")
for (i in 1:length(files)){
data <- read_excel(paste0("C:\\path", files[i]))}
I typically run this code iteration when reading about 100 or so .xls/.xlsx files into a dataframe with unnest
. Never a problem - now, when trying to do over 2000 files or so, I get the error Error:
rId1not found
- I read that this could be because one of the files is an older format - but I confirmed all excel files are .xls (97-2003 Worksheet) or .xlsx (more modern) - the format I typically read when doing 100 or so files at a time.
I have attempted my usual iteration in the above code, and then a newer one with a for loop in the below with no luck around the rId1 error. What could be happening?
files2 <-
list.files(path = "C:\\path",pattern = "*xls", full.names = TRUE) %>% basename()
data <- tibble(Customer = files2) %>% # create a data frame
mutate(file_contents = map(Customer,
~ read_excel(file.path("C:\\path", .), col_types = "text")) # a new data column and convert to text
)
files <-
list.files(path = "C:\\path", pattern = "*xls")
for (i in 1:length(files)){
data <- read_excel(paste0("C:\\path", files[i]))}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论