| To: | "Patrick Joseph" <patrick_nospam@hotmail.com> |
|---|---|
| Subject: | Re: (non)-evaluation of an optional argument |
| From: | "David L Lorenz" <lorenz@usgs.gov> |
| Date: | Thu, 15 Jul 2004 07:55:32 -0500 |
| Cc: | s-news@lists.biostat.wustl.edu, s-news-owner@lists.biostat.wustl.edu |
Patrick,
The more common way I've seen of doing what you want is to replace the
first line in your function with:
dots <- list(...)
That gives you the values associated with the arguments. The match.call()
function can tell you what was specified at the command line, but does not
evaluate the arguments. So when you type b=9 as an argument, S-PLUS can
interpret the value of b to be 9, but when you type b=tmp, it cannot
interpret tmp as a number. You could force S-PLUS to recognize it by using
eval(dots$b).
Dave
"Patrick Joseph"
<patrick_nospam@hotmail.c To:
s-news@lists.biostat.wustl.edu
om> cc:
Sent by: Subject: [S]
(non)-evaluation of an optional argument
s-news-owner@lists.biosta
t.wustl.edu
07/14/2004 09:07 PM
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
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | (non)-evaluation of an optional argument, Patrick Joseph |
|---|---|
| Next by Date: | Re: (non)-evaluation of an optional argument, Agin . Patrick |
| Previous by Thread: | (non)-evaluation of an optional argument, Patrick Joseph |
| Next by Thread: | Re: (non)-evaluation of an optional argument, Agin . Patrick |
| Indexes: | [Date] [Thread] [Top] [All Lists] |