Skip to content

control errors in vap_*() #227

@jmbarbone

Description

@jmbarbone

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)
    }
  )
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions