From gregor.gorjanc at gmail.com  Sun Jul  2 22:21:48 2006
From: gregor.gorjanc at gmail.com (Gregor Gorjanc)
Date: Sun, 02 Jul 2006 22:21:48 +0200
Subject: [Rd] Test for argument in ...
In-Reply-To: <Pine.GSO.4.56.0607021220220.8511@durian.statsci.com>
References: <44A71AB1.4000804@bfro.uni-lj.si>
	<971536df0607011856m10f64854qd8f42c5de15d7387@mail.gmail.com>
	<44A73690.5060205@bfro.uni-lj.si>
	<971536df0607012019n183955fen188287d184c9d03e@mail.gmail.com>
	<44A7A33C.3010402@bfro.uni-lj.si>
	<Pine.GSO.4.56.0607021220220.8511@durian.statsci.com>
Message-ID: <44A82ADC.1060900@bfro.uni-lj.si>

Bill Dunlap wrote:
> On Sun, 2 Jul 2006, Gregor Gorjanc wrote:
> 
>> Yes, this works.
>>
>> Thanks Gabor!
>>
>> Gabor Grothendieck wrote:
>>> That's because you are passing the argument twice.  Try this:
>>>
>>>> foo1 <- function(x, ...)
>>> + {
>>> +  L <- list(...)
>>> +  if (is.null(L$decreasing)) L$decreasing <- TRUE
>>> +  do.call(order, c(list(x), L))
>>> + }
>>>> foo1(c(5, 2, 3, 4), decreasing=FALSE)
>>> [1] 2 3 4 1
> 
> How does this differ from
>    foo2 <- function(x, ..., decreasing=TRUE)
>       order(x, ..., decreasing = decreasing)
> ?

I agree, but I wanted to learn ... argument in a more general way. That
was just an example - not a good one as you have showed.

>> x<-c(5,2,3,4)
>> identical(foo2(x), foo1(x))
> [1] TRUE
>> identical(foo2(x,decreasing=F), foo1(x,decreasing=F))
> [1] TRUE
>> identical(foo2(x,decreasing=T), foo1(x,decreasing=T))
> [1] TRUE

-- 
Lep pozdrav / With regards,
    Gregor Gorjanc

----------------------------------------------------------------------
University of Ljubljana     PhD student
Biotechnical Faculty
Zootechnical Department     URI: http://www.bfro.uni-lj.si/MR/ggorjan
Groblje 3                   mail: gregor.gorjanc <at> bfro.uni-lj.si

SI-1230 Domzale             tel: +386 (0)1 72 17 861
Slovenia, Europe            fax: +386 (0)1 72 17 888

----------------------------------------------------------------------
"One must learn by doing the thing; for though you think you know it,
 you have no certainty until you try." Sophocles ~ 450 B.C.



[Rd] Test for argument in ...
Gregor Gorjanc