I am attempting to use the methodology document here to load all the sheets in an Excel document: Read all worksheets in an Excel workbook into an R list with data.frames
The issue, however, is that I only want to load specific columns from those sheets, rather than loading everything and subsetting the columns I want.
I have tried the following:
library(readxl)
read_excel_allsheets<-function(filename){
sheets<-readxl::excel_sheets(filename)
x<-lapply(sheets, function(X) readxl::read_excel(filename,
sheet=X,
range = cell_cols(c("A", "B", "C"))))
names(x)<-sheets
x
}
dat<-read_excel_allsheets(myexcelsheet.xlsx)
The script works, but it is still reading all the columns. The named columns are present and in the same position in every sheet. Any thoughts? Thanks!