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 <pda...@gmail.com> wrote: > > On 12 Aug 2014, at 08:29 , Simon Knapp <sleepingw...@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@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....@cbs.dk Priv: pda...@gmail.com > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel