[R] do.call("+", ...)

Peter Dalgaard p.dalgaard at biostat.ku.dk
Mon Nov 20 14:59:08 CET 2006


Robin Hankin <r.hankin at noc.soton.ac.uk> writes:

> On 17 Nov 2006, at 15:09, Peter Dalgaard wrote:
> 
> [discussion of ..1 vs list(...)[[1]] snipped]
> 
> 
> >
> > Try
> >
> > g <- function(...) list(...)[[1]]
> > h <- function(...) ..1
> >
> > g((print("Hey")), (print("Joe")))
> > h((print("Hey")), (print("Joe")))
> >
> > and you should become enlightened. Bonus points for figuring out why I
> > parenthesized the arguments.
> >
> >
> 
> 
> I see the difference between g() and h(), but
> AFAICS the parentheses make no difference:

Try dropping the intermediate assignment to jj. 

> h((print("Hey")), (print("Joe")))
[1] "Hey"
[1] "Hey"
> h(print("Hey"), (print("Joe")))
[1] "Hey"
>

(The invisible() implied by print() kicks in in this case, but with
g() it is eaten internally. For the 2nd argument it really doesn't
matter in either case.)
 
> 
> 
>  > jj <- g((print("Hey")), (print("Joe"))) ; jj
> [1] "Hey"
> [1] "Joe"
> [1] "Hey"
>  >
>  > jj <- g(print("Hey"), print("Joe")) ; jj
> [1] "Hey"
> [1] "Joe"
> [1] "Hey"
>  >
>  >
>  > jj <- h((print("Hey")), (print("Joe"))) ; jj
> [1] "Hey"
> [1] "Hey"
>  >
>  > jj <- h(print("Hey"), print("Joe")) ; jj
> [1] "Hey"
> [1] "Hey"
>  >
> 
> 
> 
> 
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton
> European Way, Southampton SO14 3ZH, UK
>   tel  023-8059-7743
> 
> 

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list