[R] help with eval

From: Whit Armstrong <whit_at_twinfieldscapital.com>
Date: Sat 14 May 2005 - 10:12:09 EST

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() {

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

my.env <- init.env()


# returns this:

# > ls(envir=my.env)

# [1] "a"

# but this does not work:

# > 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.


        [[alternative HTML version deleted]]

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat May 14 10:10:41 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:46 EST