jsonlite
jsonlite copied to clipboard
Enabling serialization of prediction models
When I try to serialize and unserialize a prediction model, I'm getting an error when I try to predict a value:
eruption.lm = lm(eruptions ~ waiting, data=faithful)
json<-serializeJSON(eruption.lm)
lin.model<-unserializeJSON(json)
newdata = data.frame(waiting=80)
predict(lin.model, newdata)
# Error:
# Error in eval(expr, envir, enclos) : could not find function "list"
Prediction model can be successfully unserialized if I put the following line after unserialize;
attr(lin.model$terms, ".Environment") <- .GlobalEnv
It would be nice if this could work by default. Problem and solution is described here: http://stackoverflow.com/questions/37236806/r-serialize-r-models-as-json/37237530#37237530