I have a folder with multiple files, some of them are .xlsx and other are pdf. and each file has a different name but have the same information. My excel files contain dataset that I need to work on but I have about 150 different files. I want to know how to open all the excel files and combine them in a unique and new excel file. But, there is a tricky part, I also need to open an specific sheet from each excel file. This is the command I've been using:
episour_data <- list.files(path = "C:/Users/mvergara/ownCloud/Matias/donnees/21-11_carnet_appro/Carnets Episourire/",
pattern = "*.xlsx",
full.names = TRUE) %>%
lapply(read_excel (sheet = "SAISIE", startRow = 8 )) %>%
bind_rows
episour_data
I also tried:
dir("C:/Users/mvergara/ownCloud/Matias/donnees/21-11_carnet_appro/Carnets Episourire/", full.names = T) %>%
map_df(read_excel)
But neither of them work.
I also tried a loop:
wd <- "C:/Users/mvergara/ownCloud/Matias/donnees/"
campaign <- "21-11"
metadata <- read.xlsx(paste0(wd,campaign,"_questionnaire/21-11_metadata.xlsx"))
meta <- tibble(groupe = NA, aliment = NA, produit = NA, poids = NA, unites = NA, prix = NA, lieu = NA)
for (i in 1:nrow(metadata)) {
epi <- metadata$epicerie[i]
id <- metadata$no[i]
data <- read.xlsx(paste0(wd,campaign,"_carnet_appro/Carnets ",epi,"/",id,"_",epi,".xlsx"), sheet = "SAISIE", startRow = 8)
meta <- bind_rows(meta, data[, 3:9])
Nothing seems to work, help please