I've been looking at the help page for eval for a while, but I can't
make sense of why this example does not work.

show.a <- function() {
  a
}

init.env <- function() {
  a <- 200
  environment()
}

my.env <- init.env()

ls(envir=my.env)

# returns this:
# > ls(envir=my.env)
# [1] "a"


# but this does not work:
eval(expression(show.a()),envir=my.env)

# > eval(expression(show.a()),envir=my.env)
# Error in show.a() : Object "a" not found
# >


The help page gives the following:

   'eval' evaluates the expression 'expr' argument in the environment
     specified by 'envir' and returns the computed value. If 'envir' is
     not specified, then 'sys.frame(sys.parent())', the environment
     where the call to 'eval' was made is used.

I would be grateful for any help.

Thanks,
Whit


	[[alternative HTML version deleted]]


