# Using mxEval() with a character vector (string) argument

1 post / 0 new
Offline
Joined: 07/31/2009 - 15:24
Using mxEval() with a character vector (string) argument

It is not uncommon to have the name of a named entity, and would like to call mxEval() to get the current value of the named entity. Let's say your named entity is called "foo". The expression mxEval("foo", model) evaluates to the character string "foo". The following helper function will do what you want to do:

omxEvalByName <- function(name, model, compute=FALSE, show=FALSE) {
if((length(name) != 1) || typeof(name) != "character") {
stop("'name' argument must be a character argument")
}
if(!is(model, "MxModel")) {
stop("'model' argument must be a MxModel object")
}
eval(substitute(mxEval(x, model, compute, show),
list(x = as.symbol(name))))
}