From vincent.goulet at act.ulaval.ca  Sat Apr  5 17:45:42 2008
From: vincent.goulet at act.ulaval.ca (Vincent Goulet)
Date: Sat, 05 Apr 2008 11:45:42 -0400
Subject: [Rd] How to create a function calling two functions with
 unknown number of parameters?
In-Reply-To: <16501233.post@talk.nabble.com>
References: <16501233.post@talk.nabble.com>
Message-ID: <8B2E6787-620C-41A0-AD29-173BF6317789@act.ulaval.ca>

Le ven. 4 avr. ? 18:03, ZT2008 a ?crit :
>
>
> ... can be used to represent unknown number of parameters passed  
> into a
> function.
>
> For example, I write a function g. g calls another function f1.
>
> For example f1 could be different random number generation function.
>
> when f1=rnorm(), it has 3 parameters n, mean and standard deviation.
>
> when f1=rexp(), it has 2 parameters n and rate.
>
> g can be defined as
>
> g <- function(f1, ...) {
> 	f1(...)
> }
>
> My problem is what about g calls two functions with unknown number of
> parameters.
>
> In this case one ... doesn't help.
>
> If I define g as follows:
>
> g <- function(f1, f2, ...) {
> 	f1(...)+f2(...)
> }
>
> It seems ... is only passed to f1, it can't be passed to f2.

You should get around what you want with something along the lines of

dots <- list(...)
argf <- formals(f)
argg <- formals(g)

and then extracting from 'dots' elements corresponding to 'argf' and  
'argg' (using their names).

HTH

>
>
> Can anybody help me? Thanks!
>
> -- 
> View this message in context: http://www.nabble.com/How-to-create-a-function-calling-two-functions-with-unknown-number-of-parameters--tp16501233p16501233.html
> Sent from the R devel mailing list archive at Nabble.com.
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

---
   Vincent Goulet, Associate Professor
   ?cole d'actuariat
   Universit? Laval, Qu?bec
   Vincent.Goulet at act.ulaval.ca   http://vgoulet.act.ulaval.ca



[Rd] How to create a function calling two functions with unknown number of parameters?
Vincent Goulet