I have a function that takes as an argument a logical statement. For example,
cpdist(fitted.model, evidence = (A == "a") & (B == "b"))
I want this function to work with various "evidence" arguments, so I wrote
ev <- paste("(", evidence.variables, "=='", sapply(evidence.values, as.character), ")",
sep = "", collapse = " & ")
cpdist(fitted.model, evidence = eval(parse(text = ev)))
This works when I call it from global environment or from within a for loop. However, I want to wrap this code in a larger function (which itself is called from within a loop). When I do that, I get the error: "Error in parse(text = ev) : object 'ev' not found".
eval() has "envir" and "enclos" arguments. I have tried setting those arguments to different environments, but it hasn't worked. Environments are still a hazy subject to me. Can anyone offer any suggestions?