Open hadley opened 6 years ago
e.g.
abort <- function(.msg, .type = NULL, ...) { cnd <- error_cnd(.type = .type, ..., .msg = .msg) stop(cnd) } abort_bad_argument <- function(arg, must, not = NULL) { msg <- glue::glue("`{arg}` must {must}") if (!is.null(not)) { msg <- glue::glue("{msg}; not {not}") } abort(msg, "error_bad_argument", arg = arg) } abort_bad_argument("x", must = "be numeric") abort_bad_argument("x", must = "be numeric", not = "logical") catch_cnd(abort_bad_argument("x", must = "be numeric"))$arg
We might want one even more specifically about types.
Just wanted to throw in a 👍 for these. I just had to write up somewhat similar functions here. glue+crayon+stop() made for a great combo but I would love some standard helpers.
e.g.
We might want one even more specifically about types.