error message with openxlsx

Viewed 536

I have 42 excel files I am bringing into R using lapply and openxlsx. The original excel files have 2 worksheets. When I try to bring them in I get the following error message: Error in read.xlsx.default(xlsxFile = x, sheet = 1) : Workbook has no worksheets

even though I am specifying sheet=1.

When I go back into each file and delete the second spreadsheet I have no problem using the code to bring in all of the files. Is this a bug with openxlsx? I used the same code last year and did not have this problem.

Code:

  #bring in all files in directory

filenames <- list.files(path="S:/Adv/Scallop Central/2016 Scallop RSA/MAB Survey/2017 Data/Leg 1/2017 MAB SURVEY LEG 1 DATA/Inclinometer/Excel",pattern=".xlsx",full.names=T)
length(filenames)

info_deptemp <- lapply(filenames, function(x) openxlsx::read.xlsx(xlsxFile=x, sheet = 1))

info_deptemp2<-rbind.fill(info_deptemp)
0 Answers
Related