[R] style question: returning multiple arguments - structure orlist
murphyk at cs.berkeley.edu
Sun Jul 29 21:37:46 CEST 2001
Re: teaching computer science - I'm surprised nobody has recommended
using the classic "Structure and Interpretation of Computer Programs",
by Abelson, Sussman, and Sussman (1984/1996)
(http://mitpress.mit.edu/sicp/sicp.html), especially since R is so
closely modelled on Scheme, the language used in this book. (SICP/Scheme
is used in the introductory CS class in Berkeley and many other
Re: list/structures - I discovered a new reason why using lists is
better than structures. Suppose you create res=structure(x,y=y,z=z).
How do you just print out x, without the corresponding attributes (which
be large)? If res=list(x=x,y=y,z=z), it's easy.
There is a more subtle advantage of the Matlab-style [x,y,z]=f() syntax
- by checking how many return arguments are on the LHS, you can decide
whether to even bother computing (yet alone returning) the "optional"
Obviously there are other ways of doing this, but I think this is quite
slick (and I have used not infrequently).
Re: coming to R from Matlab - I am not trying to write Matlab-like R
code (although sometimes I can't help it :), but rather to learn the
stylistic conventions of the R community (which, I am pleased to see,
seems very concerned with writing elegant code).
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