From bolker at zoo.ufl.edu  Tue Oct 28 20:40:49 2003
From: bolker at zoo.ufl.edu (Ben Bolker)
Date: Tue Oct 28 20:26:51 2003
Subject: [Rd] proposal for "strict" versions of subsetting operators
In-Reply-To: <Pine.LNX.4.44.0310281722150.9637-100000@gannet.stats>
Message-ID: <Pine.LNX.4.44.0310281428550.25441-100000@bolker.zoo.ufl.edu>

 
  You may think this is ridiculous, but here's the situation I'm thinking
about.

  Students are trying (e.g.) to evaluate a likelihood for a series of 
parameter values, and want to store the results in a vector, e.g.:

pvec = seq(0,10,by=0.1)
likvec = numeric(length(pvec))

  They try something like

for (p in pvec) {
   likvec[p] = likfun(p)
}

rather than

for (pctr in 1:length(pvec)) {
   p = pvec[pctr]; likvec[pctr] = likfun(p)
}

I am perfectly aware that they could just do sapply(pvec,likvec) instead,
and that they will be in trouble with other parameter vectors like
seq(1,100,by=4) which will not put the answers where they want them.  
Nevertheless, this is a trap my students fall into.

  I can imagine that implicit floor() is convenient, which is why I was
suggesting this "feature" as an option, FALSE by default -- similar to the
check.bounds option.

  Ben Bolker

On Tue, 28 Oct 2003, Prof Brian Ripley wrote:

> You would need at least a fuzz for computed indices being slightly 
> non-integer (although the calling code should do that).
> 
> I can think of several cases where the implicit floor() is convenient.
> Can you tell me of examples where users would do this by accident (or out 
> of non-RTFM)?
> 
> On Tue, 28 Oct 2003, Ben Bolker wrote:
> 
> > 
> >   On a related topic: is there any chance/any interest in a slight 
> > modification of the subsetting code that would generate a warning when the 
> > user tried to subset with a non-integer?  The current behavior is that the 
> > non-integer is coerced to an integer, which means that e.g. x[3.8] is 
> > equivalent to x[3].  I can't think of (or find in the documentation) any 
> > time when this would actually be a desired behavior.
> >   The only integer-testing behavior that I can find in the code base is in 
> > some of the discrete-distribution code ...
> 
> Yes, but then they are documented that way, and selection is documented to 
> do as.integer().
> 
> >   I might be able to hack this myself -- it looks as though ExtractSubset 
> > in subset.c might be the place to do this ...
> > 
> >    Ben Bolker
> > 
> > 
> > 
> 
> 

-- 
620B Bartram Hall                            bolker@zoo.ufl.edu
Zoology Department, University of Florida    http://www.zoo.ufl.edu/bolker
Box 118525                                   (ph)  352-392-5697
Gainesville, FL 32611-8525                   (fax) 352-392-3704


[Rd] proposal for "strict" versions of subsetting operators
Ben Bolker