简体   繁体   English

read.xlsx'loadWorkbook(文件)出错:找不到文件'R

[英]read.xlsx 'Error in loadWorkbook(file): Cannot find file' R

I am trying to read in a number of Excel files into R using read.xlsx using the xlsx package but when I do so I am getting the following error: 我正在尝试使用xlsx包使用read.xlsx将大量Excel文件读入R中,但是当我这样做时,我收到以下错误:

Error in loadWorkbook(file) : Cannot find id100.xlsx loadWorkbook(file)出错:找不到id100.xlsx

First I list the files in the directory: 首先,我列出目录中的文件:

> files <- list.files(datDir, pattern = ".xlsx")

Then I use read.xlsx to read them all in: 然后我使用read.xlsx将它们全部读入:

 for (i in seq_along(files)) {
    assign(paste("id", i, sep = "."), read.xlsx(files[i],1,as.data.frame=TRUE, 
    header=FALSE, stringsAsFactors=FALSE, na.strings=" "))
 }

I checked to see if the file was even in the list and it is: 我检查了文件是否在列表中,它是:

> files
  [1] "id100.xlsx" "id101.xlsx" etc...

> files[1]
  [1] "id100.xlsx"

I have used this code many times before today and for some reason it is just not working. 我在今天之前多次使用过这段代码,由于某些原因它只是不起作用。 I keep getting that error. 我一直在收到这个错误。 Does anyone have any suggestions? 有没有人有什么建议?

Thanks! 谢谢!

如果您的工作目录与datDir不同,您应该使用full.names=T如下所示:

files <- list.files(datDir, pattern = ".xlsx",full.names=T)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM