Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions R/spec_builder.R
Original file line number Diff line number Diff line change
Expand Up @@ -754,17 +754,27 @@ create_tbl <- function(doc, cols) {
sheets_to_error <- mismatch_per_sheet %>%
keep(names(.) %in% closest_sheets)

# Write out the error
sheets_to_error %>%
map2_chr(names(sheets_to_error), function(vars, sheet_name) {
paste0(
"Sheet '", sheet_name, "' is the closest match, but unable to match the following column(s)\n",
paste(names(vars), collapse = "\n")
)
}) %>%
paste0(collapse = "\n") %>%
paste0("Unable to identify a sheet with all columns.\n", .) %>%
(call. <- FALSE)
# 1. Check for "where" columns
has_where_col <- sheets_to_error %>%
map_lgl(~ any(stringr::str_detect(names(.x), stringr::regex("^where", ignore_case = TRUE)))) %>%
any()

# 2. Generate the formatted list of sheet matches
sheet_details <- sheets_to_error %>%
purrr::imap_chr(~ {
paste0("Sheet '", .y, "' is missing: ", paste(names(.x), collapse = ", "))
})

# 3. Use cli_abort with bullets to replace the standard Error: prefix
cli_abort(
c(
"x" = "Unable to identify a sheet with all columns.",
"i" = "Closest matches identified:",
"*" = sheet_details,
if (has_where_col) c("!" = "Tip: A 'where' column was detected. Check if {.arg where_sep_sheet} is set correctly.")
),
call = NULL
)
} else if (length(matches) == 1) {
# Check names and write a better warning message if names don't work
ds_nm <- matches[[1]] %>% names()
Expand Down
Loading