I'm trying to write an R function that would create and run an OpenMx model. I can do this for a simple one factor model. I read in a data.frame for the data and construct all the paths and then do an mxRun. This works regardless of the number of variables in the data.frame. But I want to generate mxAlgebra statements (and other statements, like including parameters in an mxCI statement) which change depending on the number of variables. I've tried using "call" and can create individual mxAlgebra statements, but I cannot get mxModel to accept them when I try to generate them in a loop. What am I missing?