s-news
[Top] [All Lists]

(non)-evaluation of an optional argument

To: s-news@lists.biostat.wustl.edu
Subject: (non)-evaluation of an optional argument
From: "Patrick Joseph" <patrick_nospam@hotmail.com>
Date: Wed, 14 Jul 2004 22:07:20 -0400

Hi,

I have a question about the evaluation of an optional argument of a function. Let:

myfct _ function(a,...) {
        dots <- match.call(expand.dots = F)$...
        print(dots)
        if(!is.null(dots$b))
                return(a + dots$b)
        else return(a)
}

When I do the call myfct(10), obviously it prints "list()" and returns 10.
When I do the call myfct(10,b=9), it prints "list(b = 9)" and returns 19. Ok.

Now if I define tmp<-9 and do the call myfct(10,b=tmp), it prints "list(b = tmp)" and returns the error message: "Error in a + dots$b: Non-numeric second operand".

Is it possible to force the evaluation of tmp when calling the function?

Thank you for any hint,
Patrick

(I'm using S-Plus 4.5 on Windows 2000)

_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN Premium http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines


<Prev in Thread] Current Thread [Next in Thread>