-1

I am having trouble uploading sheets from my excel file into R. I followed another code I saw on how to read multiple sheets at once. The code I have used:

sheets <- read_xl::excel_sheets(filename.xlsx)
  x <- lapply(sheets, function(x) read_xl::read_excel(filename.xlsx, sheet = x))
  if(!tibble) x <- lapply(x, as.data.frame)
  names(x) <- sheets
  x
}

when i try to then run the following line of code:

mysheets <- read_xl_all_sheets("filename.xlsx")

I get: Error in loadNamespace(x) : there is no package called ‘read_xl’

I have installed dplyr and called readxl from the library

What could be going wrong here?

camille
  • 16,432
  • 18
  • 38
  • 60
sajtyrr
  • 15
  • 3
  • 2
    I guess it is `readxl` – akrun Jan 28 '22 at 16:40
  • what do you mean? – sajtyrr Jan 28 '22 at 16:41
  • 4
    I meant the package name is `readxl` instead of `read_xl`. Please check [here](https://cran.r-project.org/web/packages/readxl/index.html) – akrun Jan 28 '22 at 16:42
  • Yes okay, so should I change my function code to: – sajtyrr Jan 28 '22 at 16:50
  • readxl::read_excel(filename... – sajtyrr Jan 28 '22 at 16:51
  • 1
    It's really important that if you're using code you've copied from somewhere else, you understand as much of it as you can and have everything written down accurately. If you're asking for help here, it's good to have done some debugging first, at least for basic typos and accurate names of things like packages. When I google "read_xl", it corrects to "readxl"—that's a good first debugging step – camille Jan 28 '22 at 16:58

1 Answers1

0

If you import the library readxl

Then your code would look like this:

library(readxl)
sheets <- excel_sheets(filename.xlsx)
x <- lapply(sheets, function(x){ 
read_excel(filename.xlsx, sheet = x)})
if(!tibble) x <- lapply(x, as.data.frame)
names(x) <- sheets
x

AugtPelle
  • 549
  • 1
  • 10