You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was wondering if it would be possible to add a check for Excel sheets?
When I miswrite the Excel sheet, I have to go investigate the Excel file, but I wrote a small helper to help for that with rlang::arg_match() that gives helpful error message.
Also, would it be possible to rename the path argument to file, just like in readr, and .name_repair to name_repair since all other arguments in read_excel() don't start with ..
Thanks
library(readxl)
read_excel(readxl_example("datasets.xlsx"), sheet="iris2")
#> Error: Sheet 'iris2' not found# Helper with consistency with readrread_excel_check<-function(file, sheet=NULL, name_repair="unique") {
if (!is.null(sheet) &&rlang::is_string(sheet)) {
all_sheets<-readxl::excel_sheets(path=path)
rlang::arg_match(sheet, all_sheets)
}
read_excel(
path=file,
sheet=sheet,
.name_repair=name_repair
)
}
read_excel_check(
readxl_example("datasets.xlsx"),
sheet="iris2",
name_repair="universal"
)
#> Error in `read_excel_check()`:#> ! `sheet` must be one of "iris", "mtcars", "chickwts", or "quakes", not#> "iris2".#> ℹ Did you mean "iris"?
Edit: This addition is costly in terms of performance. For a small datasets, it increases computing time by ~30%, but it reduces when the data is larger, and only check is sheet is not NULL
Hi,
I was wondering if it would be possible to add a check for Excel sheets?
When I miswrite the Excel sheet, I have to go investigate the Excel file, but I wrote a small helper to help for that with
rlang::arg_match()
that gives helpful error message.Also, would it be possible to rename the
path
argument tofile
, just like in readr, and.name_repair
toname_repair
since all other arguments inread_excel()
don't start with.
.Thanks
Created on 2023-04-14 with reprex v2.0.2
Edit: This addition is costly in terms of performance. For a small datasets, it increases computing time by ~30%, but it reduces when the data is larger, and only check is
sheet
is notNULL
The text was updated successfully, but these errors were encountered: