R: How to read multiple xlsx files? Error: `path` does not exist:

Guys I need your help.

I want to read a bunch of xlsx files, but for some reason it is not working.
My code follows some suggestions given in other stack overflow posts.
I apologise but there is no reproducible code, I am totally lost here.

tbl <-
  list.files(path = 'Data/', pattern = "*.xlsx") %>% 
  map_df(~read_excel(.))

Output: Error: `path` does not exist: ‘CRO-ALL-COUNTRIES.xlsx’

Now, if I run only the line

list.files(path = 'Data/', pattern = "*.xlsx")

Result: 
>  list.files(path = 'Data/', pattern = "*.xlsx")
[1] "CRO-ALL-COUNTRIES.xlsx"  
[2] "Direct-material-packaging-ALL-COUNTRIES.xlsx"   
[3] "Direct-material-Raw-material-ALL-COUNTRIES.xlsx"

I obtain all the files that are in that folder and CRO-ALL-COUNTRIES.xlsx is there!!!
Why can't I read it?

Try this:

list.files(path = 'Data/', pattern = "*.xlsx", full.names = TRUE)
1 Like

It worked like a charm. Thank you.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.