Search code examples
rexcelreadxl

R: Cannot Read All Worksheets in Excel


See below readxl::readxl_example() that I am attempting to copy:

path <- readxl::readxl_example("datasets.xls")
lapply(readxl::excel_sheets(path), readxl::read_excel, path=path)

The above obviously works, and I'm essentially trying to recreate for my own work, below:

df2016<- readxl::read_excel("data_2016.xlsx")
lapply(readxl::excel_sheets(df2016), readxl::read_excel, df2016= df2016)

When I run my code, I return the below error: Error: path must be a string


Solution

  • Instead of reading the excel, provide the location in the lapply function. For example:

    location <- "D:/data_2016.xlsx"
    lapply(readxl::excel_sheets(location), readxl::read_excel, path=location)