'How to read multiple files from multiple directories with here
I have an R project located in a root folder and I would like to open all excel files that are in the subfolders of the project. All these subfolders have an identifiable pattern. From the existing threads, this is what I tried so far:
library(here)
library(readxl)
dirs <- list.dirs()
dirs <- dirs[grepl("^./SDG.*", dirs)]
df.list <- lapply(dirs, read_excel)
The 'dirs' object contains all the subfolders I need to look through, but I get an error after the lapply function:
Error in file(con, "rb") : cannot open the connection
In addition: Warning message:
In file(con, "rb") : cannot open file './SDG 1': Permission denied
I also tried to look through one folder at a time but I also get an error:
file.list <- list.files(here("SDG 1"), pattern='*.xlsx')
df.list <- lapply(file.list, read_excel)
Error: `path` does not exist: ‘Filename.xlsx’
I cannot simply open all excel files across all folders as I do not want to have the Excel files from the root folder of the project. Thanks in advance
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
