Reads a document of a call, {"$function": "ns::f", "arguments": {...}}, and
checks it without running the function: its form, that "$function" names one
of the functions f, each argument against its parameter's type, the versions
of "$types" when the document holds it, and, when every argument holds, the
function's rules, with the defaults written as constants of the arguments it
omits. A rule that reads an omitted argument whose default is written in R,
which the function evaluates when it runs, is listed in the attribute
unchecked, as rule_unchecked.
Arguments
- f
A typed function of
new_function(), or a list of them: the functions that the document may call. The document never selects other code.- json
Character: The document, one string or its lines.
- load
Optional Character: Packages to load before the check, as
r8from_json()takes them.
Value
A data frame of the problems, as the condition of
r8call_from_json() holds them (code, path, rule, message, and
others), with no rows for a call that holds. Paths are JSON Pointers into
the document, such as /arguments/lo. The attribute unchecked holds, in
the same form, the rules that read an omitted argument whose default is
written in R, which the function checks when it runs.
Examples
op <- options(r8.namespace = "demo")
clip <- new_function(
"clip",
function(x = arg_vec(type_double()), lo = arg_double(), hi = arg_double()) {
pmin(pmax(x, lo), hi)
},
rules = list(order = rule(lo <= hi))
)
r8check_call(clip, '{"$function": "demo::clip", "arguments": {"x": [1], "lo": 2, "hi": 1}}')#> code path rule rule_index message where suggestion hint
#> 1 rule_violation /arguments order 0 <NA> <NA>
#> diagnosis
#> 1 lo, hi, lo = 2, hi = 1options(op)