Hi,

I have a question about the usage of eval(). Wonder if any experienced user can help me out of it.

I use eval() in the following function:
semireg.pwl <- function(coef.s=rnorm(1),coef.a=rnorm(1),knots.pos=knots.x,knots.ini.val=knots.val){
  knotn <- length(knots.pos)
  def.par.env <- sys.frame(1)
  print(def.par.env)
  print(environment(coef.s))
  tg <- eval( (parse(text=
                     paste(
                           "function(coef.sex=coef.s,coef.age=coef.a,",
                           paste("knot.val.",1:knotn,"=knots.ini.val[",1:knotn,"]",sep="",collapse=","),
                           ")",
                           "{\n print(sys.frame());print(coef.sex)\n  y <- c(",
                           paste("knot.val.",1:knotn,sep="",collapse=","),
                           ")\n",
                           "  -loglikelihood(coef.sex,coef.age,knots.pos,y)\n}",
                           sep="",collapse=""
                           )
                     )
               )
             ,envir=def.par.env)
  print(tg())
  print(coef.s)
  print(sys.frame(1))
  mle(tg)
}

But when I ran semireg.pwl(), I got correct value for tg(), but an message 
"Error in eval(expr, envir, enclos) : Object "coef.s" not found" 
for mle(tg). I just don't know how to make the environment variable visible for mle().

Thanks a lot!

Feng
	[[alternative HTML version deleted]]


