[R] style question: returning multiple arguments - structure or list

Kevin Murphy murphyk at cs.berkeley.edu
Fri Jul 27 23:18:42 CEST 2001

I have a question about what is considered good style in R.

I have a function  which returns several arguments, say [x,y,z]=f(),
where sometimes I only care about the first few
(so in Matlab, I can write e.g., [x,y] = f()).

In R, there seem to be 2 ways to write this, both unsatisfying (to me):

f <- function() {
res <- f()
x <- res$x; y <- res$y; z <- res$z

f <- function() {
x <- f()
y <- attr(x,"y"); z <- attr(x, "z")

Which  is considered better style, or does it just depend on the

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list