Skip to contents

Writes the document of a call of f with the arguments given, checked as r8check_call() checks a document: {"$function": "ns::f", "$types": {...}, "arguments": {...}}, in RFC 8785 form, with "$types" holding the version of each named type that the arguments contain. The arguments are matched to the parameters as R matches a call, and only the arguments given are written.

Usage

r8call_to_json(...)

Arguments

...

The typed function of new_function(), unnamed and first, then the arguments, as the call of the function takes them.

Value

Character: The document, of class json; an invalid argument raises r8_argument_error.

Examples

op <- options(r8.namespace = "demo")
clip <- new_function(
  "clip",
  function(x = arg_vec(type_double()), lo = arg_double(default = 0), hi = arg_double()) {
    pmin(pmax(x, lo), hi)
  }
)
doc <- r8call_to_json(clip, c(-1, 0.5, 3), hi = 1)
doc
#> {"$function":"demo::clip","$types":{},"arguments":{"hi":1,"x":[-1,0.5,3]}} 
r8call_from_json(clip, doc)
#> [1] 0.0 0.5 1.0
options(op)