'Reading multiple excel files from folder in R, Error in file(con, "r") : invalid 'description' argument
I have this code that I run in R regularly to read excel files from T&E folder and put into dataframe, but suddenly it has stopped working. My excel files are not open, also I have updated my R and Rstudios.
setwd("C:\\My Directory")
inputFiles = list.files(path = "T&E/", pattern="*.xlsx")
inputFiles = paste0("T&E/", inputFiles)
loadData = function(sheetName) {
Files = lapply(inputFiles, read.xlsx, sheet = sheetName)
data = data.frame(stringsAsFactors = F)
for(i in 1:length(Files)) {
data = rbind(data, Files[[i]])
}
return(data)
}
d1 = loadData('Air')
This is the error that comes up after i call the function
Error in file(con, "r") : invalid 'description' argument
In addition: Warning message:
In unzip(xlsxFile, exdir = xmlDir) : error 1 in extracting from zip file
I also did traceback()
12: file(con, "r")
11: readLines(x, warn = FALSE, encoding = "UTF-8")
10: readUTF8(workbookRelsXML)
9: paste(readUTF8(workbookRelsXML), collapse = "")
8: read.xlsx.default(X[[i]], ...)
7: FUN(X[[i]], ...)
6: lapply(inputFiles, read.xlsx, sheet = sheetName) at filename.r#57
5: loadData("Air") at filename.r#67
4: eval(ei, envir)
3: eval(ei, envir)
2: withVisible(eval(ei, envir))
1: source("C:/Users/myname/Downloads/filename.r", echo = TRUE)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
