HARPgroup / HARParchive

This repo houses HARP code development items, resources, and intermediate work products.
1 stars 0 forks source link

problems with `serializeJSON()` #1325

Open rburghol opened 2 months ago

rburghol commented 2 months ago

An empty json object is created when using the following code (from lm_analysis_plots.R )

data_lm <- mon_lm_stats(sample_data,y_var,x_var,mo_var)
json_data_lm <- prettify(
  serializeJSON(data_lm), 
  indent = 2
)

The issue appears to be caused by the fact we are returning an R6 plotbin object, and R6 objects don't appear to serialize correctly. They may need som special plumbing in the class definition.

One option, since the embedded lm objects CAN be serialized by themselves:

serializeJSON(data_lm$atts$lms[[1]])
{"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["coefficients","residuals","effects","rank","fitted.values","assign","qr","df.residual","xlevels","call","terms","model"]},"class":{"type":"character","attributes":{},"value":["lm"]}},"value":[{"type":"double","attributes":{"names":{"type":"character","attributes":{},"value":["(Intercept)","mo_data[, x_var]"]}},"value":[83.07822491,1.38540634]},{"type":"double","attributes":{"names":{"type":"character","attributes":{},"value":["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46",
...

Maybe we should simply serialize each LM into a separate json file? I DID verify that we can convert that serialized LM back into an actual lm object, and view the residual plots. Also a note about viewing residual plots: #1326 So test:

json_data_lm <- serializeJSON(data_lm$atts$lms[[1]])

data_lm_from_json <- unserializeJSON(json_data_lm)
plot(data_lm_from_json)
rburghol commented 2 months ago

See my newest here https://github.com/HARPgroup/HARParchive/pull/1328

COBrogan commented 2 weeks ago

Since we continued to have problems with plotBin and fromJSON, I merged some new code here. This appears to successfully write all data to JSON and read it from JSON using arrays and regular expression.