From gunter.berton at gene.com  Tue Aug 12 16:30:43 2014
From: gunter.berton at gene.com (Bert Gunter)
Date: Tue, 12 Aug 2014 07:30:43 -0700
Subject: [Rd] Define 'in' for new class
In-Reply-To: <4C06649A-38B1-47B3-9B7D-F5F0D2393E16@gmail.com>
References: <CAA+5f=1yhAbDL9ndk75A88UrBujFZ1DdfY7Q0AO1OODH6-zeZA@mail.gmail.com>
	<4C06649A-38B1-47B3-9B7D-F5F0D2393E16@gmail.com>
Message-ID: <CACk-te3FNEABxBaB-4r_A5K3yNw=8UFXBCD_QAdJ6YPMVJPkKw@mail.gmail.com>

See the 'iterators' package on CRAN.

-- Bert

Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
Clifford Stoll




On Tue, Aug 12, 2014 at 12:28 AM, peter dalgaard <pdalgd at gmail.com> wrote:
>
> On 12 Aug 2014, at 08:29 , Simon Knapp <sleepingwell at gmail.com> wrote:
>
>> Hi List,
>>
>> Is it possible to define how 'in' works for an object of a specific class
>> (to achieve a similar result to implementing the iterator protocol in a
>> class Python)?
>>
>
> No, because 'in' doesn't really exist, it is "syntactic sugar" to sweeten a call to the "for" function with its three arguments. E.g.
>
>> `for`(i,1:2,print(i))
> [1] 1
> [1] 2
>
> So what you're really asking for is something like a `for` with class dispatch or the two first arguments replaced by an iterator mechanism. That's not in the cards, at least at the moment, but I suppose it isn't completely out of the question either -- ideas of this sort get bandied around occasionally. It would require changes to R's internals; it is not something you can do in (say) a package.
>
>
>> Cheers,
>> Simon Knapp
>>
>>       [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Define 'in' for new class
Bert Gunter