[R] assigning from multiple return values

Jack Tanner ihok at hotmail.com
Wed Jun 23 20:45:12 CEST 2004


I know that if I have a function that returns multiple values, I should
do return(list(foo, bar)). But what do I do on the recieving end?

fn <- function(x) {
   return(list(foo, bar))
}

I know that at this point I could say

values.list <- fn(x)

and then access

values.list[1]
values.list[2]

But that's hideous. I'd rather be able to say something like

list(local_foo, local_bar) <- fn(x)

and have the right thing happen. I realize that it's my responsibility
to not screw up and say instead

list(local_bar, local_foo)

Any suggestions?

-JT




More information about the R-help mailing list