I am writing a function which takes as its argument a fitted lavaan object. This function will manipulate the data somewhat, perform the same analysis on the manipulated data, and then do some comparisons (fit, loadings, whatever). I can see that the basic call to lavaan is available in lavInspect(fit, "call") and all the optional specifications are in lavInspect(fit, "options"). But...
(1) I do not see where the model specification is stored (i.e., that you feed to lavaan along with the data and the options). Also,
(2) lavInspect(fit, "data") loses track of which variables are ordered. And in general,
(3) I cannot figure out how to generate a new call to lavaan that replicates the old call precisely.
Basically, I want to do the following, but I don't know how to do any of it:
My_Data <- lavInspect(fit, "data") # oops, lost track of which variables are ordered
## the function will magically modify the data. Pay no attention to the man behind the curtain.
My_Model <- lavInspect(fit, "model") # oops, that doesn't exist
My_Options <- ## no idea... every specification from "call" and "options" other than data and model
new_fit <- lavaan(model = My_Model, data = My_Data, My_Options) # no idea how to make the options right here
Thanks in advance for any help. I am very new to R (and therefore lavaan), so please forgive if this is very simple.