| to_json | R Documentation |
fitverse Object to JSONConverts a fitverse object to a JSON string. Useful for passing
fit results to web front-ends, storing results in document databases, or
integrating with REST APIs.
The serialisation uses toJSON() on the output of
as.list.fitverse(), which strips non-serialisable internals
(raw optimiser fit objects, closures, environments) and returns a flat,
portable representation.
to_json(x, pretty = TRUE, ...)
## S3 method for class 'fitverse'
to_json(x, pretty = TRUE, ...)
x |
An object with a |
pretty |
Logical: if |
... |
Additional arguments passed to |
Requires the jsonlite package (listed in Suggests).
An informative error is raised if it is not installed.
The JSON output includes:
best_fit: distribution key, method, parameter estimates,
loglik, AIC, BIC.
ranking: full ranking data frame.
data_summary: descriptive statistics.
n, xlab, criterion.
The raw data vector is deliberately not included to keep the output compact and privacy-friendly for web contexts.
A single character string containing the JSON representation of x.
Karuna G. Reddy karuna.reddy@auckland.ac.nz
M. G. M. Khan mgm.khan@usp.ac.fj
as.list.fitverse for the underlying list conversion.
fromJSON to parse the JSON back to R.
if (requireNamespace("jsonlite", quietly = TRUE)) {
set.seed(42)
x <- rgamma(300, shape = 2, rate = 0.5)
fit <- fitverse(x, plot = FALSE, verbose = FALSE)
json_str <- to_json(fit)
cat(substr(json_str, 1, 400))
# Round-trip back to R list
lst <- jsonlite::fromJSON(json_str)
lst$best_fit$params
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.