can implement a tryCatch() and control error messages better
do_vap <- function(.x, .f, .value, ..., .nm) {
.x <- set_names(.x, names(.x) %||% .x)
tryCatch(
vapply(X = .x, FUN = .f, FUN.VALUE = .value, ..., USE.NAMES = .nm),
simpleError = function(e) {
mc <- match.call(
definition = sys.function(sys.parent(5L)),
call = sys.call(sys.parent(5L)),
expand.dots = TRUE,
envir = parent.frame(6L)
)
msg <- conditionMessage(e)
if (grepl("values must be type", msg, fixed = TRUE)) {
msg <- sub(
"FUN(X[[1]])",
paste0("'", deparse1(mc$.f), "'"),
msg,
fixed = TRUE
)
stop(new_condition(msg, "vapType"))
}
stop(msg, call. = mc)
}
)
}
can implement a
tryCatch()and control error messages better