Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable localized check makers for quosure-checks #45

Closed
egnha opened this issue Jun 7, 2017 · 1 comment
Closed

Enable localized check makers for quosure-checks #45

egnha opened this issue Jun 7, 2017 · 1 comment

Comments

@egnha
Copy link
Owner

egnha commented Jun 7, 2017

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().

  • Solution 1: One possibility would be substitute the function of the boolean flag dot_as_expr with a special (prefix/suffix) “marker” in the error message, which is interpreted by err_invalid_input().

  • Solution 2: Alternatively, a simpler, but arguably more “hacky,” approach would be endow localized checkers with an additional “global name” attribute that would be interpreted by parse_check() as overriding the value of the argument msg. In this case, it would suffice for chkrs to behave accordingly:

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

    No change would then be required elsewhere, and the logic of localize() would be simplified as well, for it would not require any naming logic.

@egnha
Copy link
Owner Author

egnha commented Jun 8, 2017

Resolved by 65bce4b, 1599591, 49ef763

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant