I have a series of excel files that I need to read. I am using the xl.read.file() because these files are password protected. However, it seems that there is a problem reading files that have special characters in their names
Create file list
file.list <- list.files(path = file.path, pattern = '*.xlsx')
Read every file in file list
df.list <- lapply(file.list, function (x) xl.read.file(paste0("Onlines_to_update/",x),password = "myPW",top.left.cell="A4"))
I get the following error:
Error in .COM(x, name, ...) :
Microsoft Excel cannot acces file "M:\Scripts\Onlines_to_update\Referència.xlsx".
However, the file Referència.xlsx exist and this problem does not occur for other files that do not have special characters in their name.
From what I have read it seems like an encoding problem. How do I tell RStudio or lapply to understand these special characters?
Additional info:
Encoding(file.list[3])
[1] "UTF-8"
The problem disappears if I bypass the paste0 function:
xl.read.file(paste0("Onlines_to_update/","Referència.xlsx"),password = "myPW",
top.left.cell="A4")
I have tried loading the with encoding ISO-8859-1 (System default) and UTF-8. None has worked.
I have also executed Sys.setlocale("LC_ALL", "Catalan") and did not worked either.
This problem has appeared after a recent update of RStudio. I was able to run the code with no problems until recently.