From murdoch.duncan at gmail.com  Wed May 28 13:34:40 2014
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Wed, 28 May 2014 07:34:40 -0400
Subject: [Rd] Ellipsis to Two Functions When One Has Nested Functions
In-Reply-To: <1401256816354.86462@uni.sydney.edu.au>
References: <1401256816354.86462@uni.sydney.edu.au>
Message-ID: <5385C9D0.5090909@gmail.com>

On 28/05/2014, 2:00 AM, Dario Strbenac wrote:
> Hello
>
> If I have a function
>
> aFunction <- function(data, alpha, ...)
> {
>      transform(alpha, ...)
>      rowMeans(data) > alpha
> }
>
> f <- function(data, selection, ...)
> {
>      selected <- selection(data, ...)
>      plot(data[selected, ], ...)
> }
>
> f(aDataset, aFunction, alpha = 10, pch = 19, transform = sqrt)
>
> and selection calls another function, which has ... and that function calls other functions, is there an easier way than getting the formals of all the functions called internally by selection, and all of the formals of functions called by plot ? Is there any option to change the error into a warning message ?

You can use try() to catch an error, but you can't ignore it.  The code 
that triggered the error will still exit at that point.

There are at least two common ways of handling the situation where you 
want to pass optional args to two different functions.  One is to use

args <- list(...)

to get all the arguments in a list, and then manually split up the list, 
and use do.call() to pass some of them on.  Generally you would do this 
only if you knew in advance how to split the args, you wouldn't try to 
call formals() to work it out at run-time.

Another way is to have an argument like "control" in optim(), and ask 
the user to pass one set of options via that, and the other via ... . 
You'd use do.call() again to construct that call.

Duncan Murdoch



[Rd] Ellipsis to Two Functions When One Has Nested Functions
Duncan Murdoch