Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading data from multiple sheets at once #45

Open
Alik-V opened this issue Apr 5, 2022 · 2 comments
Open

Reading data from multiple sheets at once #45

Alik-V opened this issue Apr 5, 2022 · 2 comments

Comments

@Alik-V
Copy link

Alik-V commented Apr 5, 2022

Hi Victor, just discovered this, looks like another terrific package from you!
I got a question regarding uploading data from an excel. Is it possible to upload data from multiple sheets at once?

@Alik-V Alik-V changed the title Multiple sheets Reading data from multiple sheets at once Apr 5, 2022
@pvictor
Copy link
Member

pvictor commented Apr 7, 2022

Hey Alik, thank you :)
Currently no, you have to select one sheet. What will be your use-case ? Same data-structure in multiple sheets ? Or retrieving a list with sheet's content ?

Victor

@Alik-V
Copy link
Author

Alik-V commented Apr 7, 2022

Hey Victor,
for the current use case the data structure would be identical in each sheet, however, I can envision some use-cases where it would be different.
I think in my ideal world, it would write all sheets into a list of dataframes and allow me to do whatever post-processing I need to do afterwards myself. This is how I do it at the moment anyway, but would love to use it in combination with the pretty modal interface of datamods 👍
On the simplest level, something like this:

upload_sheet_data <- function(datapath) {
  # Names of the sheets present in the upload file
  sheet_names <- readxl::excel_sheets(path = datapath)
  # Empty list that will have dataframes appended to it
  upload_list <- list()
  # Loop for each sheet
  for (sheet in sheet_names) {
    # Read the sheet
    data <- readxl::read_xlsx(datapath, sheet = sheet)
    # Bind the data from the sheet to the list
    upload_list[[sheet]] <- data 
  }
  return(upload_list)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants