egnha / valaddin

Functional input validation to make R functions more readable and robust
Other
33 stars 1 forks source link

Enable localized check makers for quosure-checks #45

Closed egnha closed 7 years ago

egnha commented 7 years ago

This issue refers to the development branch.

Example:

chkrs <- localize(isTRUE, "{{.}} not scalar (length is {length(.)})" = {length(.) == 1L})

should produce the list of two functions such that

chkrs[[1]](x, y)
#> ~isTRUE ~ list(`FALSE: isTRUE(x)` = ~x, `FALSE: isTRUE(y)` = ~y)

chkrs[[2]](x, "Not scalar" = y)
#> ~{length(.) == 1L} ~ list(`x not scalar (length is {length(.)})` = ~x, `Not scalar` = ~y)

NB It is crucial that the predicate remains a quosure—it must remember its original scope.

As such, the error message won't be properly interpreted by the current implementation of err_invalid_input(), because that function relies on the flag dot_as_expr which is set by parse_check(), and is invisible in the output, above.

Consequently, the mechanism by which the proper scope of dot-interpolation is identified will need to be adapted to the above behavior of localize().

egnha commented 7 years ago

Resolved by 65bce4b6c5db7064fec1e94b1cbad04717962890, 159959143fd951053a733ca1e5663e69f88b8b4d, 49ef763c2dc803d3eb7dad090183c7da91aa3272