I'm writing a code to read data from a directory. The files have different extensions such as xlsx, xls, CSV etc. I'm using if else conditions to read different formats. My snippet to read xlsx files is as follows:
inputPath = "C:/work1/Apple/Data/LA/Test/L3"
if(str_detect(string = inputPath, pattern = ".xlsx")) {
dataInput = read.xlsx(xlsxFile = filePath,
sheet = 1)}
When I run this code, I get an error like this and the traceback is as follows:
Error in file(description = xlsxFile) : invalid 'description' argument
4.
file(description = xlsxFile)
3.
getFile(xlsxFile)
2.
read.xlsx.default(xlsxFile = inputPath, sheet = 1)
1.
read.xlsx(xlsxFile = inputPath, sheet = 1)
I have created this input path as follows:
identifier = "Test"
dataDirPath = file.path(getwd(), "Data/LA", identifier)
mode = "L3"
inputPath = list.files(file.path(dataDirPath, mode), full.names = TRUE)
inputPath contains this:
> inputPath
[1] "C:/work1/Apple/Data/LA/Test/L3/12303?????????(???????).xlsx"
[2] "C:/work1/Apple/Data/LA/Test/L3/12306?????????(???????).xlsx"
[3] "C:/work1/Apple/Data/LA/Test/L3/12309?????????(???????).xlsx"
[4] "C:/work1/Apple/Data/LA/Test/L3/12312?????????(???????).xlsx"
[5] "C:/work1/Apple/Data/LA/Test/L3/34503?????????(???????).xlsx"
[6] "C:/work1/Apple/Data/LA/Test/L3/34506?????????(???????).xlsx"
[7] "C:/work1/Apple/Data/LA/Test/L3/34509?????????(???????).xlsx"
[8] "C:/work1/Apple/Data/LA/Test/L3/34512?????????(???????).xlsx"
[9] "C:/work1/Apple/Data/LA/Test/L3/56703?????????(???????).xlsx"
>
One thing is that the files in this directory contains japanese characters and some numbers. Here in the above inputPath output, '?' actually contains japanese characters. But code doesn't read it.
Note: I have set the locales to Japanese at the start itself.
For example,
1234林檎.xlsx
Is there anything wrong here?