尝试将多个Excel文件读取到数据框架中时会出现错误

发布于 2025-02-10 06:37:59 字数 849 浏览 1 评论 0原文

通常,当阅读大约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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文