bison2178
bison2178

Reputation: 789

r batch reading xls files from specific sheet

I have around 30 excel files in my folder.

I am interested in reading them all.

I used this code below

library(readxl)
file.list <- list.files(pattern='*.xlsx')
df.list <- lapply(file.list, read_excel)

The problem is each excel file has multiple sheets and I am interested in the contents of only one sheet , sheetName = "Piano", not interested in the contents of other sheets.

So how can I ensure that in addition to reading all the 30 excel files r reads only data from sheetName="Piano" from all these excel files. Thanks.

Upvotes: 1

Views: 307

Answers (1)

akrun
akrun

Reputation: 887661

We can make use of the sheet argument of read_excel. According to ?read_excel

sheet - Sheet to read. Either a string (the name of a sheet), or an integer (the position of the sheet). Ignored if the sheet is specified via range. If neither argument specifies the sheet, defaults to the first sheet.

library(dplyr)
library(readxl)
df.list <- map(file.list, read_excel, sheet = 'Piano')

Upvotes: 2

Related Questions