From hb at stat.berkeley.edu  Wed Oct 17 03:10:41 2007
From: hb at stat.berkeley.edu (Henrik Bengtsson)
Date: Tue, 16 Oct 2007 18:10:41 -0700
Subject: [Rd] Fwd: Digest package - make digest generic?
In-Reply-To: <66f3bd910710161359t4a1580ecl9bc2ec1191560cd7@mail.gmail.com>
References: <f8e6ff050710150751r5d9add21sdb3ebccdb93ed085@mail.gmail.com>
	<59d7961d0710151300i1aed80adx448642f6161b3d29@mail.gmail.com>
	<f8e6ff050710151348x8888784lc6e5c5b5cf7e2bd@mail.gmail.com>
	<59d7961d0710151405w1b78c2bl81f08da87e62207e@mail.gmail.com>
	<66f3bd910710160524g3ef0f207h30f5f6bdf2880110@mail.gmail.com>
	<66f3bd910710160525o697104a8y90e9c8bf4c3255d1@mail.gmail.com>
	<18197.781.298239.228245@ron.nulle.part>
	<66f3bd910710161300w1857acd9gfdd038c389077dec@mail.gmail.com>
	<f8e6ff050710161322g69214d7dv9fa4672280404e9c@mail.gmail.com>
	<66f3bd910710161359t4a1580ecl9bc2ec1191560cd7@mail.gmail.com>
Message-ID: <59d7961d0710161810r5e3c8f10o2155dffa47ee20ac@mail.gmail.com>

Hi,

if there is a need for a digest0(), which there seems to be, we should
have one, but we should find a better name.

A better approach may be to keep digest() as is and introduce
hashCode() for the feature Hadley requested, e.g.

hashCode <- function(...) UseMethod("hashCode");
hashCode.default <- function(...) digest(...);

Personally, I think hashCode() is a more descriptive term of the
value/outcome whereas digest() describes the action.  Of course, some
of the arguments of digest() should be excluded from hashCode(), but
the above gives you the idea.

That would make the distinction clear, and it is very much in line how
Java is doing it (sorry Dylan folks).  I think the Java got a useful
setup with its hashCode() & equals() methods.  If you want the
details, here is one reference:

  http://www.geocities.com/technofundo/tech/java/equalhash.html

but the short story is that <quote>two objects that are "equal" must
produce the same hash code as long as they are equal, however unequal
objects need not produce distinct hash codes.</quote>.  The equals()
relationship should be reflexive, symmetric, transitive, consistent.
For details, see above URL.  These rules are very useful, but requires
quite a bit of effort from the developer/maintainer in order to keep
it up to date and valid.

Cheers

Henrik






On 10/16/07, Roger Peng <rdpeng at gmail.com> wrote:
> Calling 'digest.default' directly would not be possible if the method
> were hidden in a namespace (without resorting to some maneuvering).
> To force the default method I think you'd need to 'unclass' the
> object.
>
> I'm not against making 'digest' generic, but I'd prefer it if there
> were a guaranteed way to compute the digest of the "raw"/full object
> without having to wonder about class-specific behavior.  Something
> like:
>
> digest0 <- [[the current 'digest' function]]
> digest <- function(object, ...) UseMethod("digest")
> digest.default <- function(object, ...) digest0(object, ...)
>
> As I think we've seen in this discussion already, what is surprising
> to one person may not be surprising to another (and vice versa) so
> having something like 'digest0' which is consistent across all R
> objects would be useful.
>
> -roger
>
> On 10/16/07, hadley wickham <h.wickham at gmail.com> wrote:
> > On 10/16/07, Roger Peng <rdpeng at gmail.com> wrote:
> > > My understanding was that Hadley wanted 'digest' to operate on part of
> > > an object rather than on the entire, which might contain uninteresting
> > > or irrelevant details.  For example, if we had
> > >
> > > a <- structure(list(x = 1, y = 2), class = "foo")
> > > b <- structure(list(x = 2342342, y = 2), class = "foo")
> > >
> > > digest.foo <- function(object, ...) digest(object$y)
> >
> > Yes, that's exactly what I want, except in my case my objects contain
> > about 20 or 30 bits of information that are irrelevant (I'm my case
> > documentation about the class and other functions), so it would be
> > surprising if p1 and p2 which produced identical plots gave different
> > digests.
> >
> > If you want the default behaviour, you could always call
> > digest.default to digest the entire object.
> >
> > Hadley
> >
>
>
> --
> Roger D. Peng  |  http://www.biostat.jhsph.edu/~rpeng/
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] Fwd: Digest package - make digest generic?
Henrik Bengtsson