1

I have sheets in a Workbook and then n number of Workbooks. These Workbooks are in a folder and I need to perform operations on sheets separately as data been incoherent.

I'm using

excelFiles <- list.files(path = path, pattern = '.*\\.xlsx', full.names = TRUE)
data_list <- import_list(excelFiles)

But this code makes a list of 'n' number of Workbooks and opens the 1st sheet on using data_list[[1]] and data_list[1]

What I need is sheets as df to perform functions and logic to go through to get them from folders.

Edit: rio is used for import_list.

Julius Vainora
  • 47,421
  • 9
  • 90
  • 102
Adi.sr
  • 161
  • 1
  • 9
  • 1
    This question is a potential duplicate. Reference [Read all worksheets in an Excel workbook into an R list with data.frames r](https://stackoverflow.com/questions/12945687/read-all-worksheets-in-an-excel-workbook-into-an-r-list-with-data-frames). – OTStats Jan 18 '19 at 13:40
  • 1
    where is the function `import_list()` from? – Chris Jan 18 '19 at 13:40
  • 1
    Is this using the Rio library? – anotherfred Jan 18 '19 at 13:41

1 Answers1

1

Apparently when we pass a list of file names that's what happens, while if we pass only a single file name it works fine. So, instead you may use

library(rio)
data_list <- lapply(excelFiles, import_list)

Then data_list is a list of elements corresponding to workbooks, and where each element is again a list of elements corresponding to sheets. So, for instance, data_list[[1]][[2]] is 1st workbook, 2nd sheet. In case you want only a list of sheets, then you may use

sheets <- unlist(data_list, recursive = FALSE)

where now sheets[[34]] is 34th sheet corresponding to who knows which workbook.

Julius Vainora
  • 47,421
  • 9
  • 90
  • 102
  • Still `Soft <- data_list[[1]]` doesn't give a sheet. I have to use `Soft1 <- Soft[[1]]` to make Soft1 a data frame. – Adi.sr Jan 18 '19 at 14:11