The XR structure requires a server-language function objectFromJSON()
which
parses an object description in JSON. Methods for generic function objectAsJSON()
should produce the appropriate string.
objectAsJSON(object, prototype = prototypeObject(), level = 1)# S4 method for array
objectAsJSON(object, prototype = prototypeObject(),
level = 1)
# S4 method for environment
objectAsJSON(object, prototype = prototypeObject(),
level = 1)
# S4 method for list
objectAsJSON(object, prototype = prototypeObject(),
level = 1)
# S4 method for envRefClass
objectAsJSON(object, prototype = prototypeObject(),
level = 1)
# S4 method for Interface
objectAsJSON(object, prototype = prototypeObject(),
level = 1)
# S4 method for AssignedProxy
objectAsJSON(object, prototype = prototypeObject(),
level = 1)
# S4 method for ProxyClassObject
objectAsJSON(object,
prototype = prototypeObject(), level = 1)
The object to be converted.
The prototype server class; see asServerObject
.
Will be 1 for top-level call, incremented when recalled for an element. Used to make choices about scalars.
A string that will be parsed according to JSON grammar.
array
: treat matrix and array objects as legitimate S3 objects
environment
: An environment is encoded with its class, in contrast to a named list
which may be a simple dictionary.
list
: A list will be encoded as a JSON list if it has no names, as a JSON
dictionary if it has all distinct, non-empty names, or with an explicit representation in
all other cases.
envRefClass
: An explicit representation that includes the fields.
Interface
: An interface object is transmitted via its character string Id,
enough to identify the object; the rest is too R-dependent to be useful.
AssignedProxy
: Gets the object back from the server, then recalls the generic.
It's usually not a good idea to get here, because bringing the proxy back and then converting
it again is not foolproof; better to make direct use of the proxy. But if a proxy object
is part of an ordinary list, environment or other R object, this method will be used.
ProxyClassObject
: Gets the object back from the server, then recalls the generic.
See the comments under the "AssignedProxy"
method.
This function is typically called from a method for asServerObject
.
Methods for objectAsJSON()
in turn often call one or both of two helper functions:
asJSONS4()
, which produces the full description of the R object; and
typeToJSON()
, which produces the code for the basic R types, ignoring all
class or attribute information.
Chambers, John M. (2016) Extending R, Chapman & Hall/CRC. ( Chapter 13, discussing this package, is included in the package: ../doc/Chapter_XR.pdf.)