[R] R design (was "Variable passed to function not used in function in select)
Terry Therneau
therneau at mayo.edu
Tue Nov 11 16:28:39 CET 2008
I've read the back and forth this morning, and I have to side with Vince.
1. Functions that re-interpret their arguments are very dangerous. The
original question involved a well formed call to a function, which returned the
wrong answer. Bug, design flaw, whatever -- it's a mistake and the best choice
would be to fix it.
I only consider such behavior in 2 cases:
a. when the function is almost never, ever, called from anything but the
top level. help() is the only example I can think of.
b. to create a label from an argument, as in plot, but the argument
itself is left alone to work as it should.
One possible fix for subset: first treat the argument formally, and only if that
simple interpretation fails try the more 'clever' interpretations. Whether this
is doable or not I can't say.
2. The documentation of subset is not in any way clear. I would never have
been able to diagnose or work around this bug. The issues are very subtle.
I quite often see "it's in the manual so we bear no blame" as an argument on
this list. We all need to remember that our view of what we are particularly
close to is a distorted one -- I for instance think that everything about the
survival package is crystal clear --- and be particularly open to concerns that
something is opaque or subtle.
3. I've heavily used perhaps 20 computing languages in my life. I found S to
be a refreshing revalation (referring to S of the 1988 Blue manual) precisely
because it was completely functional. Once I got used to it, this feature made
it so much more useful, extensible, understandable than other things I'd used.
R is becoming less and less a functional language (hidden functions and
dependencies with environments for one), I quite often cannot figure out either
exactly what a function calls or how to get it to stop doing it. I am not sure
we have gained with each choice of "convenience" or sophistication over
functional purity. I want "scan(file=myfile)" to continue to return "variable
myfile not found" when I forget the quotes.
I am stumped by the R results I get too often, and I'm not a novice. That
said, good design is hard. I spend a lot of time on that aspect in the survival
package and there are still bits where the 'right' way is only clear after
several years experience. I do occassionaly make non-backwards compatable
changes. The R core team has done an amazing job on the whole.
And let's not shoot the bearers of bad news.
Terry T
More information about the R-help
mailing list