tags:

views:

37

answers:

2

I have a function that requires both a S4 object and a data frame as arguments.

But functions like lapply and llply will only allow one list and one function. example: new_list=llply(list, function)

I could make a single list with alternating S4 object and data but llply will push one list item at a time which means that it will either be the S4 object or the data (the function cannot perform with just one or the other).

In some sense what I am looking for is akin to a 2D list (where each row has the S4 obj and data and a row gets pushed through at a time).

So how would I make this work?

Here's a more general version of my problem. If I have a function like so:

foobar <- function(dat, threshold=0.5, max=.99)
{
...
}

and I wanted to push a list through this function, I could do:

new_list=llply(list, foobar)

but if I also wanted to pass a non-default value for threshold or max, how would I do so in this context?

A: 

May be you can try this:

Make each list item itself a list, which contains a S4 object and a data frame.

Just a suggestion, I'm not quite sure if this works.

Gary Lee
A: 

Functions like lapply typically have a ... parameter of arguments which get passed to the function. Eg:

lapply(list, foobar, somearg='nondefaultvalue')

If you have multiple varying parameters (eg a different somearg value for each element in list), then you would either pack them as pairs in a list, or turn to a function like mapply:

mapply(foobar, list, somearg=c('vectorof', 'nondefault', 'values')
Charles