[Rd] ranges and contiguity checking
William Dunlap
wdunlap at tibco.com
Wed May 12 20:53:47 CEST 2010
> -----Original Message-----
> From: r-devel-bounces at r-project.org
> [mailto:r-devel-bounces at r-project.org] On Behalf Of Duncan Murdoch
> Sent: Wednesday, May 12, 2010 11:35 AM
> To: bullard at stat.berkeley.edu
> Cc: r-devel at stat.math.ethz.ch
> Subject: Re: [Rd] ranges and contiguity checking
>
> On 12/05/2010 2:18 PM, James Bullard wrote:
> > Hi All,
> >
> > I am interfacing to some C libraries (hdf5) and I have
> methods defined for
> > '[', these methods do hyperslab selection, however, currently I am
> > limiting slab selection to contiguous blocks, i.e., things
> defined like:
> > i:(i+k). I don't do any contiguity checking at this point,
> I just grab the
> > max and min of the range and them potentially do an
> in-memory subselection
> > which is what I am definitely trying to avoid. Besides
> using deparse, I
> > can't see anyway to figure out that these things (i:(i+k)
> and c(i, i+1,
> > ..., i+k)) are different.
> >
> > I have always liked how 1:10 was a valid expression in R
> (as opposed to
> > python where it is not by itself.), however I'd somehow
> like to know that
> > the thing was contiguous range without examining the un-evaluated
> > expression or worse, all(diff(i:(i+k)) == 1)
You could define a sequence class, say 'hfcSeq'
and insist that the indices given to [.hfc are
hfcSeq objects. E.g., instead of
hcf[i:(i+k)]
the user would use
hcf[hfcSeq(i,i+k)]
or
index <- hcfSeq(i,i+k)
hcf[index]
max, min, and range methods for hcfSeq
would just inspect one or both of its
elements.
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
>
> You can implement all(diff(x) == 1) more efficiently in C,
> but I don't
> see how you could hope to do any better than that without
> putting very
> un-R-like restrictions on your code. Do you really want to say that
>
> A[i:(i+k)]
>
> is legal, but
>
> x <- i:(i+k)
> A[x]
>
> is not? That will be very confusing for your users. The problem is
> that objects don't remember where they came from, only arguments to
> functions do, and functions that make use of this fact mainly
> do it for
> decorating the output (nice labels in plots) or making error messages
> more intelligible.
>
> Duncan Murdoch
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
More information about the R-devel
mailing list