[R] Why doesn't vec[-real.number] give an error or warning? Kids do the darndest things!

S Ellison S.Ellison at lgc.co.uk
Mon Mar 15 03:31:15 CET 2010

>>> Bryan Hanson <hanson at depauw.edu> 03/14/10 2:39 AM >>>
>Under what circumstances would the documented behavior be valuable?  

<Inserts tongue in cheek:>
It would be useful in all the circumstances in which it would be
sensible to use a real number as a vector index.

Not that I can think of any.

Somebody else might, though. And it is possible that someone might
calculate intended integer values from reals, leading to a real vector
of indices. Under those circs, returning an error or warning wouldn't be
helpful. So in this case R is kind of treating users like grown-ups who
are assumed to know what they're doing. 

It's also pedagogically (is that a word?) useful. Users who confuse
reals with integers may remember the lesson better if it fouls up their
entire script with a problem that takes hours to track down than if it
generates a polite warning they don't understand but accommodate by
changing the script. And that kind of difference is occasionally
terribly important in statistics and in general computing. So maybe it
is useful to be allowed to foul up occasionally.

<removes tongue from cheek>

Steve E

This email and any attachments are confidential. Any use...{{dropped:8}}

More information about the R-help mailing list