Last active
November 22, 2022 08:44
-
-
Save alekrutkowski/47856f1969d1c1463661fdae8d049c53 to your computer and use it in GitHub Desktop.
Helper functions to the R package `openxlsx2`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(openxlsx2) | |
| library(magrittr) # for the %>% operator | |
| # Import all sheets in the Excel file as a list of data.frames | |
| # like in the previous package version (openxlsx) | |
| readAllSheets <- function(xlsx_file_name, drop_empty_sheets=TRUE, | |
| suppress_warnings=TRUE, ...) | |
| xlsx_file_name %>% | |
| read_sheet_names() %>% | |
| sapply(function(x) | |
| try(`if`(suppress_warnings,suppressWarnings,identity) | |
| (read_xlsx(xlsx_file_name,x,...)), silent=TRUE) %>% | |
| `if`(inherits(.,'try-error') && | |
| attr(.,'condition')$message=='dims are inf:-inf', # empty worksheet | |
| `if`(!drop_empty_sheets, data.frame()) | |
| ,.), | |
| simplify=FALSE) %>% | |
| .[!sapply(.,is.null)] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment