I need to import a list of .xls files into R. Fairly standard operation, using file.list and purrr, done several times before. For some reason I cannot use readxl package as I keep getting libxls error, so switched to XLConnect, that seems to work.
However, using the following code:
file.list <- list.files('./Raw/', pattern = '.xls', full.names = TRUE)
rws <- function(x) {XLConnect::readWorksheetFromFile(x, sheet = 1, startRow =4)}
df <- purrr::map_dfr(file.list,rws, .id = "source")
I get an output, where source
column includes position of the file in the list (1,2,3,...), not name of the file. What is the problem?
try to do it this way
file.list <- list.files('./Raw/', pattern = '.xls', full.names = TRUE) %>%
purrr::set_names()
rws <- function(x) {XLConnect::readWorksheetFromFile(x, sheet = 1, startRow =4)}
df <- purrr::map_dfr(file.list,rws, .id = "source")