CachedFit takes an expression to evaluate (presumably a model fitting call, but it could be anything), and the filename to which to save the fitted model. If the RDS object exists, it loads it instead of fitting the object. It does not check to make sure that the expression corresponds to that which resulted in the original model fit.

CachedFit(expr, rds_filename, save_only = F)

Arguments

expr

An expression (e.g., {lm(y ~ x, data = aDataFrame)}) to be evaluated.

rds_filename

A filename (full path, or filename in current working directory) to save or load using saveRDS or loadRDS.

save_only

Set to TRUE if you want the result to be saved, but don't want the object to be returned (default is FALSE)

Value

the return value of expr or the object saved in the RDS object located at rds_filename. If save_only is TRUE, returns TRUE, or an object of class try-error if the call resulted in an error.