Here's the code I'm using:
library(readxl)
setwd(file.path(dirname("~"), "/Shared Documents/Programs/Data and Reporting/Data Quality Reports/Org Level Data"))
lst = list.files(pattern="*.xlsx")
df = data.frame()
for(table in lst){
dataFromExcel <- read_excel(table, sheet = "Project Summary")
df <- rbind(df,dataFromExcel)
}
write.csv(df, "_Project Level data.csv")
I basically know nothing about R, and simply mashed together code from a couple sites, editing what little I understood.
Here's the scenario: I have a bunch of Excel files that I download and put into a folder called "Org Level Data". I run this script and it creates a new file with all the data in each file's "Project Summary" sheet. However, it errors out if one of those files does not contain a sheet called "Project Summary", which will be quite a few files. I can get around this by removing those files from the folders, but I'd really like this script to just skip those files and ignore them, if possible.
I saw something about read_excel_safely but I cannot figure out how to insert that into my code, since I understand very little about the "read_excel" and "rbind" sections.
I tried adding , na = "---") to the read_excel() function, thinking that it would handle that not existing, but it'd didn't add or take away anything from the script running.
I've also looked into trying to make lst check for that "Project Summary" sheet when being created, but I don't know how to do that.