From h.wickham at gmail.com  Fri Dec 11 14:26:03 2015
From: h.wickham at gmail.com (Hadley Wickham)
Date: Fri, 11 Dec 2015 07:26:03 -0600
Subject: [Rd] How do I reliably and efficiently hash a function?
In-Reply-To: <CAM2gKPbSZjLUpVW87iaKczF-2eDHiT6GReu28SBJ98mSt8Djcg@mail.gmail.com>
References: <CAM2gKPbSZjLUpVW87iaKczF-2eDHiT6GReu28SBJ98mSt8Djcg@mail.gmail.com>
Message-ID: <CABdHhvGzA9atxR2Mrei_T+0h9L3u2LKaDu3GwAi5tr71Q0=Omw@mail.gmail.com>

On Thu, Dec 10, 2015 at 5:49 PM, Konrad Rudolph
<konrad.rudolph+r-devel at gmail.com> wrote:
> I?ve got the following scenario: I need to store information about an
> R function, and retrieve it at a later point. In other programming
> languages I?d implement this using a dictionary with the functions as
> keys. In R, I?d usually use `attr(f, 'some-name')`. However, for my
> purposes I do not want to use `attr` because the information that I
> want to store is an implementation detail that should be hidden from
> the user of the function (and, just as importantly, it shouldn?t
> clutter the display when the function is printed on the console).
>
> `comment` would be almost perfect since it?s hidden from the output
> when printing a function ? unfortunately, the information I?m storing
> is not a character string (it?s in fact an environment), so I cannot
> use `comment`.
>
> How can this be achieved?
>
> For reference, I?ve considered the following two alternatives:
>
> 1. Use `attr`, and override `print.function` to not print my
> attribute. However, I?m wary of overriding a core function just to
> implement such a little thing, and overriding this function would
> obviously clash with other overrides, if somebody else happens to have
> a similarly harebrain idea.

Why not use your own S3 class?

Hadley

-- 
http://had.co.nz/



[Rd] How do I reliably and efficiently hash a function?
Hadley Wickham