Skip to content

Call and Eval function inside R

3 messages · Narayani Barve, Luca Morandini, Michael Sumner

#
On 07/12/2011 10:29 PM, Narayani Barve wrote:
The call function's arguments are evaluated at definition, hence hourval should be 
defined beforehand.

An exmaple:

remove(c(a, b, c))
fmean<-call("mean", c(a, b, c)) # Error, a,b,c are not defined

a<-1
b<-2
c<-3
fmean<-call("mean", c(a, b, c)) # OK, a,b,c are defined

g<-function(f) {
  eval(f)
}

g(fmean) # Returns 2

a<--1
b<-0
c<-1

g(fmean) # Returns 2 as well, since a,b,c are evaluated at definition time

Regards,

Luca Morandini
http://www.lucamorandini.it
#
Please don't cross post:

http://stackoverflow.com/questions/6671029/call-and-eval-function-inside-r

This is not a question for R-Sig-Geo at any rate, R-help is a better
candidate and you should consult that mailing list's posting guide.

Cheers, Mike.
On Wed, Jul 13, 2011 at 6:29 AM, Narayani Barve <narayani at ku.edu> wrote: