Arguments
- mix
A mixture object to be saved to JSON.
- con
A connection specifying where the JSON will be written to or read.
- ...
Additional arguments passed to the
jsonlite::toJSON()
andjsonlite::fromJSON()
function for writing and reading, respectively.- rescale
A logical value indicating whether to rescale the mixture weights so that they sum to 1. Defaults to
TRUE
.
Value
The write_mix_json
function does not return a value while
the read_mix_json
returns the mixture object stored in the
connection specified.
Details
The mixture objects are written or read from the connection
con
, which can be a character string specifying a file
path or a connection object as detailed in
base::connections()
.
When writing mixture objects as JSON it is strongly recommended to
explicitly set the number of digits (argument digits
) to be
used for the numerical representation in order to control the
accuracy of the JSON representation of the mixture object. If the
mixture object inherits from the "EM"
class (as is the
case when the mixture is created using the
mixfit()
function), then the mixture object
will be cast to a simple mixture object such that diagnostics
from the "EM"
fitting procedure are dropped from the
object. For easier readability the user is encouraged to set the
argument pretty=TRUE
, which is passed to the
jsonlite::toJSON()
function and makes the output more
human readable.
Note that when reading in mixture objects, then these are not
necessarily equal to the mixtures passed to the write_mix_json
function. This is a consequence of the limited precision of the
textual representation as defined by the digits
argument.