Closed egnha closed 7 years ago
Need to replace quos()
with a analogue of dots_definitions()
that supports splicing of definitions. (dots_definitions()
only splices dots.)
Something like this will do the trick:
vld <- function(...) {
dd <- rlang::dots_definitions(...)
c(normalize_checks(dd$dots), label_checks(dd$defs))
}
label_checks <- function(defs)
lapply(defs, `names<-`, c("msg", "chk"))
normalize_checks <- function(dots) {
is_chk <- vapply(dots, is_check, logical(1))
dots_splice <- lapply(dots[is_chk], rlang::eval_tidy)
dots_checks <- lapply(dots[!is_chk], msg_empty)
c(dots_checks, dots_splice)
}
is_check <- function(.)
is.list(rlang::f_rhs(.))
msg_empty <- function(.)
list(msg = rlang::quo(NULL), chk = .)
Then adapt the parser, accordingly.
The error message needs to capture its calling environment, because it may need to be interpolated by
glue()
. Therefore, we need to usedots_definitions()
, rather thanquos()
, when capturing checks (in eitherfirmly()
orfasten()
).Corrected API should look like